title: No service for type 'Microsoft.AspNetCore.Identity.RoleManager error
body: <p>I'm setting up user roles on a ASP.NET CORE 2.1 application. But when I try to use the RoleManager it shoots into error. The error I get is: </p>
  
  <pre><code>No service for type 'Microsoft.AspNetCore.Identity.RoleManager`1[Microsoft.AspNetCore.Identity.IdentityRole]' has been registered.)'
  </code></pre>
  
  <p>I've looked through the whole application to see if <code>IdentityUser</code> is still anywhere, since I've created a class that inherits from it ( ApplicationUser ), but everything else seems correct. Adding <code>services.AddIdentity&lt;ApplicationUser, IdentityRole&gt;()
   .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;()
   .AddDefaultTokenProviders();</code> 
  gives a runtime error stating: <code>NotSupportedException: Store does not implement IUserRoleStore&lt;TUser&gt;.</code> Adding <code>Service.AddDefaultIdentity()</code>instead of <code>AddIdentity()</code>doesn't work either.</p>
  
  <pre><code>public class Startup
  {
  
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
          {
              // This lambda determines whether user consent for non-essential cookies is needed for a given request.
              options.CheckConsentNeeded = context =&gt; true;
              options.MinimumSameSitePolicy = SameSiteMode.None;
          });
  
          //services.AddDbContext&lt;ApplicationDBContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString("ApplicationDBContextConnection")));
  
  
          //services.AddDefaultIdentity&lt;ApplicationUser&gt;().AddRoles&lt;IdentityRole&gt;().AddEntityFrameworkStores&lt;ApplicationDBContext&gt;();
  
          services.Configure&lt;IdentityOptions&gt;(options =&gt;
          {
              // Password settings
              options.Password.RequireDigit = true;
              options.Password.RequiredLength = 8;
              options.Password.RequireNonAlphanumeric = false;
              options.Password.RequireUppercase = true;
              options.Password.RequireLowercase = false;
              options.Password.RequiredUniqueChars = 6;
  
              // Lockout settings
              options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
              options.Lockout.MaxFailedAccessAttempts = 10;
              options.Lockout.AllowedForNewUsers = true;
  
              // User settings
              options.User.RequireUniqueEmail = true;
          });
  
          services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager&lt;ApplicationUser&gt; userManager)
      {
  
  
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler("/Home/Error");
              app.UseHsts();
          }
  
          app.UseHttpsRedirection();
          app.UseStaticFiles();
          app.UseCookiePolicy();
          app.UseAuthentication();
  
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
          });
  
          CreateUserRoles(userManager).GetAwaiter().GetResult();
      }
      private async Task CreateUserRoles( UserManager&lt;ApplicationUser&gt; userManager)
      {
  
          var UserManager = userManager;
  
          //Assign Admin role to the main User here we have given our newly registered 
          //login id for Admin management
          ApplicationUser user = await UserManager.FindByEmailAsync("test@test.com");
          UserManager.AddToRoleAsync(user, "Admin").GetAwaiter().GetResult();
      }
  }
  </code></pre>