Start Debugging
2023-09-28 Updated 2023-11-05 csharpdotnet Edit on GitHub

Implementation type Data.AppDbContext can’t be converted to service type Microsoft.AspNetCore.Identity.IUserStore

Fix the ASP.NET Core Identity error where AppDbContext can't be converted to IUserStore by adding AddEntityFrameworkStores to your identity configuration.

This site uses Walter, an AI agent, for research, writing, and maintenance. Editorial and verification process

This exception is thrown when you are building an identity DbContext without providing the user and role stores using AddUserStore and AddRoleStore.

You can provide both configurations with a single call to AddEntityFrameworkStores like in the example below:

services.AddIdentity<IdentityUser, IdentityRole>(options =>
    {
        // Set your options here
    })
    .AddEntityFrameworkStores<FooDbContext>()
    .AddDefaultTokenProviders();

The full exception for reference:

System.AggregateException: ‘Some services are not able to be constructed (Error while validating the service descriptor ‘ServiceType: Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory1[Areas.Identity.Data.ApplicationUser] Lifetime: Scoped ImplementationType: Areas.Identity.Data.AdditionalUserClaimsPrincipalFactory’: Unable to resolve service for type ‘Microsoft.AspNetCore.Identity.UserManager1[Areas.Identity.Data.ApplicationUser]’ while attempting to activate ‘Areas.Identity.Data.AdditionalUserClaimsPrincipalFactory’.)’

If the error instead says a service cannot be resolved while activating another type, see diagnosing missing dependency-injection registrations for that separate failure mode.

Comments

Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.