{"record":{"id":"4928334e3142fbd9","repo":"fullstackhero/dotnet-starter-kit","slug":"role-store-not-configured-ensure-addroles-fshrole-and-ef","errorCode":null,"errorMessage":"Role store not configured. Ensure .AddRoles<FshRole>() and EF stores.","messagePattern":"Role store not configured\\. Ensure \\.AddRoles<FshRole>\\(\\) and EF stores\\.","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"src/Modules/Identity/Modules.Identity/Features/v1/Roles/RoleService.cs","lineNumber":63,"sourceCode":"            .ToListAsync(cancellationToken);\n\n        foreach (var userId in directUserIds.Concat(groupUserIds).Distinct())\n        {\n            await userPermissionService.InvalidatePermissionCacheAsync(userId, cancellationToken).ConfigureAwait(false);\n        }\n    }\n\n    public async Task<PagedResponse<RoleDto>> GetRolesAsync(\n        int pageNumber = 1,\n        int pageSize = 20,\n        string? search = null,\n        CancellationToken cancellationToken = default)\n    {\n        if (roleManager is null)\n            throw new NotFoundException(\"RoleManager<FshRole> not resolved. Check Identity registration.\");\n\n        if (roleManager.Roles is null)\n            throw new NotFoundException(\"Role store not configured. Ensure .AddRoles<FshRole>() and EF stores.\");\n\n        var page = Math.Max(1, pageNumber);\n        var size = Math.Clamp(pageSize, 1, 200);\n\n        var query = roleManager.Roles.AsNoTracking();\n        if (!string.IsNullOrWhiteSpace(search))\n        {\n            var needle = search.Trim().ToLowerInvariant();\n            query = query.Where(r =>\n                (r.Name != null && r.Name.ToLower().Contains(needle))\n                || (r.Description != null && r.Description.ToLower().Contains(needle)));\n        }\n\n        var total = await query.LongCountAsync(cancellationToken).ConfigureAwait(false);\n        var rows = await query\n            .OrderBy(r => r.Name)\n            .Skip((page - 1) * size)\n            .Take(size)","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/fullstackhero/dotnet-starter-kit/blob/3f2959e683e9f83f13e55e1678c9119f63c7e8e5/src/Modules/Identity/Modules.Identity/Features/v1/Roles/RoleService.cs#L45-L81","documentation":"RoleService.GetRolesAsync checks that roleManager.Roles (the IQueryable from the role store) is not null. A null queryable means Identity was registered without a role store (no .AddRoles<FshRole>() with EF stores backing it), so the service throws NotFoundException('Role store not configured. Ensure .AddRoles<FshRole>() and EF stores.').","triggerScenarios":"Calling the roles list endpoint on an Identity registration that omitted AddRoles<FshRole>() or the EF role store, causing RoleManager.Roles to be null.","commonSituations":"Trimmed-down Identity setup copied from a minimal sample (users only, no roles); swapping to a custom role store that returns null Roles; a module registration refactor that dropped AddRoles from the IdentityBuilder chain.","solutions":["Ensure the IdentityBuilder chain includes .AddRoles<FshRole>() before .AddEntityFrameworkStores<TContext>()","Verify the EF identity stores are registered with the module's DbContext","Check for custom RoleManager/store registrations that may shadow the EF store"],"exampleFix":"// before\nservices.AddIdentity<FshUser, FshRole>()\n    .AddEntityFrameworkStores<IdentityDbContext>();\n// after\nservices.AddIdentity<FshUser, FshRole>()\n    .AddRoles<FshRole>()\n    .AddEntityFrameworkStores<IdentityDbContext>();","handlingStrategy":"validation","validationCode":"// startup check\nusing var scope = app.Services.CreateScope();\nvar rm = scope.ServiceProvider.GetRequiredService<RoleManager<FshRole>>();\nif (rm.Roles is null) throw new InvalidOperationException('Role store missing: add .AddRoles<FshRole>() with EF stores');","typeGuard":"bool RoleStoreConfigured(RoleManager<FshRole>? rm) => rm?.Roles is not null;","tryCatchPattern":"try { var roles = await roleService.GetRolesAsync(1, 20); }\ncatch (Exception e) when (e.Message.Contains(\"Role store not configured\")) { logger.LogError(e, \"Identity role store misconfigured\"); throw; }","preventionTips":["Keep .AddRoles<FshRole>() in the IdentityBuilder chain","Add a health/startup check asserting RoleManager.Roles is queryable","Copy Identity registration from a known-good module config when in doubt","Cover role listing in an integration test that fails on misconfiguration"],"tags":["identity","roles","configuration"],"backgroundTag":"missing-dependency","analyzedSha":"3f2959e683e9f83f13e55e1678c9119f63c7e8e5","analyzedAt":"2026-09-15T22:20:53.684Z","contentChangedAt":"2026-09-15T22:20:53.684Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}