title: No service for type 'Microsoft.AspNetCore.Identity.RoleManager registered NET 6
body: <p>Getting this error for some re</p>
  <blockquote>
  <p>InvalidOperationException: No service for type
  'Microsoft.AspNetCore.Identity.RoleManager`1[TenDSecurity.Domain.Identity.Models.AppRole]'
  has been registered.
  Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider
  provider, Type serviceType)</p>
  </blockquote>
  <p>This is a snippet of my program.cs</p>
  <pre><code>var connectionName = &quot;connectionStringName&quot;;
  var builder = WebApplication.CreateBuilder(args);
  var connectionString = builder.Configuration.GetConnectionString(connectionName);
  builder.Services.AddDbContext&lt;AppDbContext&gt;(options =&gt; 
      options.UseSqlServer(connectionString, providerOptions =&gt; providerOptions.EnableRetryOnFailure(3)));
  builder.Services
      .AddIdentity&lt;AppUser, AppRole&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 = 1;
          //User Settings
          //options.User.RequireUniqueEmail = true;
          //options.User.AllowedUserNameCharacters = &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&quot;;
          //Sign In settings
          //options.SignIn.RequireConfirmedAccount = true;
  
          //Lockout Settings
          options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(60);
          options.Lockout.MaxFailedAccessAttempts = 5;
      })
      .AddEntityFrameworkStores&lt;AppDbContext&gt;()
      .AddDefaultTokenProviders();
  builder.Services
      .ConfigureApplicationCookie(options =&gt;
      {
          // Cookie settings
          //options.Cookie.HttpOnly = true;
          //options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
  
          options.LoginPath = &quot;/Identity/Account/Login&quot;;
          options.LogoutPath = &quot;/Identity/Account/Logout&quot;;
          options.AccessDeniedPath = &quot;/Identity/Account/AccessDenied&quot;;
          options.SlidingExpiration = true;
      });'
  </code></pre>
  <p>custom user Identity Contexts</p>
  <pre><code>public class AppDbContext : IdentityDbContext&lt;AppUser, AppRole, short, AppUserClaims, AppUserRoles, AppUserLogins, AppRoleClaims, AppUserTokens&gt;
  {
      public AppDbContext(DbContextOptions&lt;AppDbContext&gt; options) : base(options)
      {
      }
  }
  </code></pre>
  <p>Exception raw</p>
  <pre><code>System.InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.RoleManager\`1[TenDSecurity.Domain.Identity.Models.AppRole]' has been registered.
      at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)    
      at Microsoft.AspNetCore.Mvc.Razor.RazorPagePropertyActivator.&lt;&gt;c__DisplayClass8_0.&lt;CreateActivateInfo&gt;b__1(ViewContext context)  
      at Microsoft.Extensions.Internal.PropertyActivator\`1.Activate(Object instance, TContext context)  
      at Microsoft.AspNetCore.Mvc.Razor.RazorPagePropertyActivator.Activate(Object page, ViewContext context)  
      at Microsoft.AspNetCore.Mvc.Razor.RazorPageActivator.Activate(IRazorPage page, ViewContext context)  
      at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)  
      at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)  
      at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter)  
      at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)  
      at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable\`1 statusCode)  
      at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable\`1 statusCode)  
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeResultAsync&gt;g__Logged|22_0(ResourceInvoker invoker, IActionResult result)  
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeNextResultFilterAsync&gt;g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)  
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)  
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
  --- End of stack trace from previous location ---
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeNextResourceFilter&gt;g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)  
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)    
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)    
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() 
  --- End of stack trace from previous location ---
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeAsync&gt;g__Logged|17_1(ResourceInvoker invoker)    
      at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeAsync&gt;g__Logged|17_1(ResourceInvoker invoker)
      at Microsoft.AspNetCore.Routing.EndpointMiddleware.&lt;Invoke&gt;g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
      at TenDSecurity.Web.Razor.Middleware.UserDestroyerMiddleware.Invoke(HttpContext httpContext, UserManager\`1 userManager, SignInManager\`1 signInManager)
          in C:\Users\jbalman\source\repos\TenDSecurity.ERM\TenDSecurity.ERM\TenDSecurity.Web.Razor\Middleware\UserDestroyerMiddleware.cs:line 33
      at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
      at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
      at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
  </code></pre>
  <p>A note  : that the UserDestroyerMiddleware is just what makes sure the user is login</p>
  <p>I'm at a loss why this doesn't work now for my old razor pages app but still works a the new Blazor UI I'm working on ( same database)</p>