"IServiceCollection" does not contain a definition for "AddSession",

I get an error when adding "AddSession" to ASP.Net Core 1.1 using VS2017.

'IServiceCollection' does not contain a definition for 'AddSession' and no extension method 'AddSession' that takes the first argument of type 'IServiceCollection' can be found (do you miss a directive or an assembly reference?)

.csproj

<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:

enter image description here

+7
source share
8 answers

The following method I fixed the problem.

  • Clean and restore solution.
  • Restart Visual Studio 2017.

Thanks @HenkMollema

+5
source

You need to enable the following Nuget package

AutoMapper.Extensions.Microsoft.Dependencyinjection

+14
source

I know it's a little late, but have you tried installing the Microsoft.AspNetCore.Session package from nuget?

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

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

It worked for me!

+6
source

The dependency versions do not seem to be synchronized. Use Nuget to upgrade all your packages to the same version, and this should fix the problem. This applies to most, if not all Microsoft packages. *.

You also need the following operators:

 using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using System; 
+2
source

Make sure you have

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

(or more current version) in the .csproj file

+1
source

In my case, AutoMapper.Extensions.Microsoft.DependencyInjection (v1 was installed). Uninstalled and installed AutoMapper.Extensions.Microsoft.DependencyInjection v5.0.1

0
source

Looks like you missed something. In the package manager console, write:

 install-package Microsoft.AspNetCore.Session -version xxx 

xxx depends on your project

0
source

Adding a nuget package for Scrutor fixed this for me

-1
source

Source: https://habr.com/ru/post/1268619/


All Articles