Aspnetcore: Microsoft.AspNetCore.Identity 3.1 package?

Created on 9 Mar 2020  路  6Comments  路  Source: dotnet/aspnetcore

I'm trying to add Microsoft.AspNetCore.Identity 3.1 package in .net standard 2.1.
I get this error at runtime:

MissingMethodException: Method not found: 'Void Microsoft.AspNetCore.Identity.SignInManager1..ctor(Microsoft.AspNetCore.Identity.UserManager1, Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory1<!0>, Microsoft.Extensions.Options.IOptions1, Microsoft.Extensions.Logging.ILogger1<Microsoft.AspNetCore.Identity.SignInManager1>, Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider)'.

I am referencing a .net standard library from an asp.net core web project. The class library contains this UserManager and SignInManager etc implementations. That class library is on .net standard 2.1 and the package installed is Microsoft.AspNetCore.Identity 2.0. I understand that I need to have the latest AspNet Core Identity package referenced, but I couldn't find that on Nuget. I stumbled upon this solution where you could add a <FrameworkReference Include="Microsoft.AspNetCore.App" /> in .net standard class library - that doesn't work either.

Answered Resolved area-identity question

All 6 comments

Yes, this is because as of most of the aspnet packages have moved into the shared framework, see https://andrewlock.net/exploring-the-microsoft-aspnetcore-app-shared-framework-in-asp-net-core-2-1-preview-1/ for a description of how things were moved from packages into the shared framework

@HaoK Thanks for getting back. Yups, I understand that and I am trying to add the shared framework reference. When I try to add <FrameworkReference Include="Microsoft.AspNetCore.App" /> to be able to use Microsoft Identity 3.1 core, in my .netstandard 2.1 class library project, I get this:

NETSDK1073 The FrameworkReference 'Microsoft.AspNetCore.App' was not recognized.

Identity became part of the framework, so you target netstandard I'm afraid.

@DamianEdwards how does someone write a class library to target aspnetcore.app?

Change the TFM to netcoreapp3.1, e.g.:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

</Project>

image

Yes, I did that and now I have Identity there in the class library. But that doesn't solve problem. Our web forms (4.7) app was previously referencing .netstandard2.0 project which had core Identity 2 package installed and thus we were able to use userManager, signInManager etc. But inferring from the above comments, I believe we can't update our .netstandard2.0 project any further because .net standard 2.1 can't have the reference to identity 3.1.

That's correct. With ASP.NET Core 3.0, the Identity bits moved ahead to .NET Core 3.0 and no longer work with .NET Framework 4.x or .NET Standard.

Was this page helpful?
0 / 5 - 0 ratings