Search code examples
asp.net-coreasp.net-core-identity

Unable to resolve service for type 'Microsoft.AspNetCore.Identity.RoleManager` While changing the datatype of AspNetUsers Id column to int


I am facing Unable to resolve service for type 'Microsoft.AspNetCore.Identity.RoleManager` problem in my Administration controller here is how I injected RoleManager in Administration Controller

        private readonly RoleManager<IdentityRole> roleManager;
        private readonly UserManager<ApplicationUser> userManager;
        public AdministrationController(RoleManager<IdentityRole> roleManager,UserManager<ApplicationUser> userManager)
        {
            this.roleManager = roleManager;
            this.userManager = userManager;
        }

And in my startup.cs file I have added Identity service like this

  services.AddIdentity<ApplicationUser, IdentityRole<int>>()
              .AddEntityFrameworkStores<CISContext>()
              .AddDefaultTokenProviders();

As you can see while adding Identity service in my startup.cs file I have added datatype in my IdentityRole class in order to change the datatype of AspNetUsers Id column from string to int

How can I solve this Issue please?


Solution

  • Just a hunch, because I haven't tested this and haven't worked with roles for a while, but have you tried to specify the generic type parameter while injecting it?

    I.e. RoleManager<IdentityRole<int>> roleManager.

    Because I noticed that you're adding it in startup.cs by specifying a non-default int key type.