Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams Trying to add AutoMapper to .NetCore1.1 - not recognising services.AddAutoMapper() (10 answers)
Closed 2 years ago .

This post was edited and submitted for review 1 year ago and failed to reopen the post:

Original close reason(s) were not resolved

I am getting an error while adding 'AddSession' in ASP.Net Core 1.1 using VS2017.

'IServiceCollection' does not contain a definition for 'AddSession' and no extension method 'AddSession' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

.csproj

The package is already installed in this solution.

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>
 <ItemGroup>
  <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
  <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
 </ItemGroup>
 <ItemGroup>
 <DotNetCliToolReference 
 Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>
 </Project>

Error :

Building seems to work fine. Visual Studio might just be off here, did you try to restart it? – Henk Mollema Jun 7, 2017 at 10:10

I know this is a bit late, but did you try to install the Microsoft.AspNetCore.Session package from nuget?

https://www.nuget.org/packages/Microsoft.AspNetCore.Session/

In Visual Studio: Install-Package Microsoft.AspNetCore.Session -Version 1.1.2(in my case)

It worked for me!

The package is already installed in the project and that you can see in my given .csproj code. Any how everything working fine and this is not an answer for me. – Rajeesh Menoth Dec 14, 2017 at 7:27

The versions of the dependencies seem to be out of sync. Use Nuget to update all your packages to be the same version and that should solve the issue. This applies to most if not all Microsoft.* packages.

Also you need the following using statements:

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;
                It's downloaded and the versions are now 1.1.2. I also done 'Clean' and 'Rebuild' but still I am facing the same Issue.
– Rajeesh Menoth
                Jun 7, 2017 at 10:54
                Yes, Three more using statements in my class using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging;
– Rajeesh Menoth
                Jun 7, 2017 at 11:06

Make sure you have

<PackageReference Include="Microsoft.AspNetCore.Session" Vesion="1.1.1" />

(or more up-to-date version) within your .csproj file.

This is meant for others who come across this post with a similar error, but different root cause. If rebooting was the fix, I would suggest deleting this question/answer as it is probably of limited use to others – coolhand Dec 26, 2017 at 21:36 Whenever people posting any questions in SO , they will mention the exact reason of the bug. Question 4 U , "Session" package already existing in the given code then why are you trying to downgrade the package version without any reason ?. – Rajeesh Menoth Dec 28, 2017 at 10:33 This is a new answer to an old question but you did not explain why Install-Package AutoMapper.Extensions.Microsoft.DependencyInjection should be run. – Mech Sep 2, 2020 at 1:31

It looks like you missed something. In Package Manager Console, write:

install-package Microsoft.AspNetCore.Session -version x.x.x

x.x.x depends on your project reference