find and solve || findandsolve.com
Please wait.....

Welcome back.






Before Read Terms of use

Some services are not able to be constructed or AspNet Core Identity configuration

Some services are not able to be constructed or AspNet Core Identity configuration

System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Identity.ISecurityStampValidator Lifetime: Scoped ImplementationType: Microsoft.AspNetCore.Identity.SecurityStampValidator`1[Microsoft.AspNetCore.Identity.IdentityUser]': Unable to resolve service for type 'AMS.Repository.AMSContext' while attempting to activate.

Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9[Microsoft.AspNetCore.Identity.IdentityUser,Microsoft.AspNetCore.Identity.IdentityRole,AMS.Repository.AMSContext,System.String,Microsoft.AspNetCore.Identity.IdentityUserClaim`1[System.String],Microsoft.AspNetCore.Identity.IdentityUserRole`1[System.String],Microsoft.AspNetCore.Identity.IdentityUserLogin`1[System.String],Microsoft.AspNetCore.Identity.IdentityUserToken`1[System.String],Microsoft.AspNetCore.Identity.IdentityRoleClaim`1[System.String]]'.) (Error while validating the service descriptor 'ServiceType:

Answer

Option 1.

You should to add

 AddEntityFrameworkStores<TContext>():
services.AddIdentity<IdentityUser, IdentityRole>()
    .AddEntityFrameworkStores<WorldContext>();

FWIW, ASP.NET Core 3.1 is not "a little outdated". Documentation referencing that version is so outdated as to be virtually useless. So much changed in 2.X, and even more in 3.X. You should find a different article/tutorial.

Option 2.

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("samplewebsettings.json");
    Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
    // Required to use the Options<T> pattern
    services.AddOptions();
    // Add settings from configuration
    services.Configure<SampleWebSettings>(Configuration);
    // Uncomment to add settings from code
    //services.Configure<SampleWebSettings>(settings =>
    //{
    // settings.Updates = 17;
    //});
    services.AddMvc();
    // Add application services.
    services.AddTransient<IDateTime, SystemDateTime>();
}

Comments



Report Response