{"record":{"id":"0ca9d2a944786356","repo":"aspnetboilerplate/aspnetboilerplate","slug":"roledisplaynameisalreadytaken","errorCode":null,"errorMessage":"RoleDisplayNameIsAlreadyTaken","messagePattern":"RoleDisplayNameIsAlreadyTaken","errorType":"exception","errorClass":"UserFriendlyException","httpStatus":null,"severity":"error","filePath":"src/Abp.ZeroCore/Authorization/Roles/AbpRoleManager.cs","lineNumber":438,"sourceCode":"            return IdentityResult.Success;\n        });\n    }\n\n    public virtual async Task<IdentityResult> CheckDuplicateRoleNameAsync(\n        int? expectedRoleId,\n        string name,\n        string displayName)\n    {\n        var role = await FindByNameAsync(name);\n        if (role != null && role.Id != expectedRoleId)\n        {\n            throw new UserFriendlyException(string.Format(L(\"RoleNameIsAlreadyTaken\"), name));\n        }\n\n        role = await FindByDisplayNameAsync(displayName);\n        if (role != null && role.Id != expectedRoleId)\n        {\n            throw new UserFriendlyException(string.Format(L(\"RoleDisplayNameIsAlreadyTaken\"), displayName));\n        }\n\n        return IdentityResult.Success;\n    }\n\n    /// <summary>\n    /// Gets roles of a given organizationUnit\n    /// </summary>\n    /// <param name=\"organizationUnit\">OrganizationUnit to get belonging roles </param>\n    /// <param name=\"includeChildren\">Includes roles for children organization units to result when true. Default is false</param>\n    /// <returns></returns>\n    public virtual async Task<List<TRole>> GetRolesInOrganizationUnitAsync(\n        OrganizationUnit organizationUnit,\n        bool includeChildren = false)\n    {\n        return await _unitOfWorkManager.WithUnitOfWorkAsync(async () =>\n        {\n            if (!includeChildren)","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/aspnetboilerplate/aspnetboilerplate/blob/2323c13a152aa0ebfb37af3830f687d7f5b53795/src/Abp.ZeroCore/Authorization/Roles/AbpRoleManager.cs#L420-L456","documentation":"AbpRoleManager.CheckDuplicateRoleNameAsync also enforces uniqueness of the role's DisplayName. It throws UserFriendlyException 'RoleDisplayNameIsAlreadyTaken' when FindByDisplayNameAsync(displayName) returns a role with a different Id than expectedRoleId.","triggerScenarios":"Creating a role whose DisplayName matches another role's, or updating a role's DisplayName to one owned by a different role.","commonSituations":"Multi-language UI where two roles share a display label; admin creating 'Manager' display name twice; upgrade scenarios where seeding added a role with the same display name as a user-created one.","solutions":["Use a unique DisplayName per tenant or resolve duplicates by changing one display name","Catch UserFriendlyException and surface the localized message in the form","Pass the role's own Id as expectedRoleId on update so self-matches pass","Consider whether your app really needs display-name uniqueness; if not, override CheckDuplicateRoleNameAsync"],"exampleFix":"// before\nawait _roleManager.CheckDuplicateRoleNameAsync(null, \"manager\", \"Manager\"); // display name taken\n// after\nvar clash = await _roleManager.FindByDisplayNameAsync(\"Manager\");\nif (clash == null) await _roleManager.CreateAsync(new TRole { Name = \"manager\", DisplayName = \"Manager\" });","handlingStrategy":"validation","validationCode":"var existing = await _roleManager.FindByDisplayNameAsync(displayName);\nif (existing != null && existing.Id != expectedRoleId)\n    throw new UserFriendlyException(string.Format(L(\"RoleDisplayNameIsAlreadyTaken\"), displayName));","typeGuard":null,"tryCatchPattern":"try { await _roleManager.CheckDuplicateRoleNameAsync(expectedRoleId, name, displayName); }\ncatch (UserFriendlyException ex) { ModelState.AddModelError(\"DisplayName\", ex.Message); return BadRequest(ModelState); }","preventionTips":["Check both name and display name before role create/update","Trim/normalize display names; avoid invisible whitespace duplicates","Decide intentionally whether display-name uniqueness matters for your tenant","Catch UserFriendlyException in your app service instead of letting it bubble raw"],"tags":["abp","role","duplicate-name","validation"],"backgroundTag":"duplicate-record","analyzedSha":"2323c13a152aa0ebfb37af3830f687d7f5b53795","analyzedAt":"2026-09-08T08:00:50.638Z","contentChangedAt":"2026-09-08T08:00:50.638Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}