I am using IdentityServer4 with ASP.NET Core 2.1 with Visual Studio 2017. I try to integrate ASP.net Identity, but I get this exception during startup: "IUserClaimsPrincipalFactory`1 not registered."
2018-06-13 22:04:30.411 +07:00 [FTL] Application startup exception
System.InvalidOperationException: Service type: IUserClaimsPrincipalFactory`1 not registered.
at Microsoft.Extensions.DependencyInjection.IdentityServerBuilderExtensions.AddDecorator[TService](IServiceCollection services)
at Microsoft.Extensions.DependencyInjection.IdentityServerBuilderExtensions.AddTransientDecorator[TService,TImplementation](IServiceCollection services) in C:\local\identity\server4\AspNetIdentity\src\IdentityServer4.AspNetIdentity\IdentityServerBuilderExtensions.cs:line 62
at Microsoft.Extensions.DependencyInjection.IdentityServerBuilderExtensions.AddAspNetIdentity[TUser](IIdentityServerBuilder builder) in C:\local\identity\server4\AspNetIdentity\src\IdentityServer4.AspNetIdentity\IdentityServerBuilderExtensions.cs:line 33
at OsjaSolutions.IdentityServer.Startup.ConfigureServices(IServiceCollection services) in C:\PROJECT\OsjaSolutions\Backend\IdentityServer\Startup.cs:line 42
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
I found the issue. I get this exception because I did not add the following line in ConfigureServicesfunction (Startup.cs)
services.AddIdentity<ApplicationUser, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I found the issue. I get this exception because I did not add the following line in
ConfigureServicesfunction (Startup.cs)services.AddIdentity<ApplicationUser, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();