{"record":{"id":"84c0ed30ddc3699b","repo":"aspnetboilerplate/aspnetboilerplate","slug":"identityresult-errors-joined-with","errorCode":null,"errorMessage":"identityResult.Errors (joined with \", \")","messagePattern":"identityResult\\.Errors \\(joined with \", \"\\)","errorType":"exception","errorClass":"UserFriendlyException","httpStatus":null,"severity":"error","filePath":"src/Abp.ZeroCore/IdentityFramework/IdentityResultExtensions.cs","lineNumber":57,"sourceCode":"                  {\"User already in role '{0}'.\", \"Identity.UserAlreadyInRole\"},\n                  {\"User is locked out.\", \"Identity.UserLockedOut\"},\n                  {\"Lockout is not enabled for this user.\", \"Identity.UserLockoutNotEnabled\"},\n                  {\"User {0} does not exist.\", \"Identity.UserNameNotFound\"},\n                  {\"User is not in role '{0}'.\", \"Identity.UserNotInRole\"}\n          };\n\n    /// <summary>\n    /// Checks errors of given <see cref=\"IdentityResult\"/> and throws <see cref=\"UserFriendlyException\"/> if it's not succeeded.\n    /// </summary>\n    /// <param name=\"identityResult\">Identity result to check</param>\n    public static void CheckErrors(this IdentityResult identityResult)\n    {\n        if (identityResult.Succeeded)\n        {\n            return;\n        }\n\n        throw new UserFriendlyException(identityResult.Errors.Select(err => err.Description).JoinAsString(\", \"));\n    }\n\n    /// <summary>\n    /// Checks errors of given <see cref=\"IdentityResult\"/> and throws <see cref=\"UserFriendlyException\"/> if it's not succeeded.\n    /// </summary>\n    /// <param name=\"identityResult\">Identity result to check</param>\n    /// <param name=\"localizationManager\">Localization manager to localize error messages</param>\n    public static void CheckErrors(this IdentityResult identityResult, ILocalizationManager localizationManager)\n    {\n        if (identityResult.Succeeded)\n        {\n            return;\n        }\n\n        throw new UserFriendlyException(identityResult.LocalizeErrors(localizationManager));\n    }\n\n    public static string LocalizeErrors(this IdentityResult identityResult, ILocalizationManager localizationManager)","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/aspnetboilerplate/aspnetboilerplate/blob/2323c13a152aa0ebfb37af3830f687d7f5b53795/src/Abp.ZeroCore/IdentityFramework/IdentityResultExtensions.cs#L39-L75","documentation":"CheckErrors is an extension on ASP.NET Core IdentityResult that surfaces any failed identity operation as an ABP UserFriendlyException. When identityResult.Succeeded is false, all error descriptions are joined with ', ' and thrown so the user sees why the operation (login, user creation, password change, role assignment) was rejected.","triggerScenarios":"Calling CheckErrors(identityResult) after UserManager/RoleManager/SignInManager operations (CreateAsync, CreateIdentityAsync, ChangePasswordAsync, AddToRoleAsync, etc.) when the underlying IIdentityResult has IsSuccess == false, e.g. duplicate user name, invalid password, concurrency stamp mismatch.","commonSituations":"Creating a user whose password violates the configured PasswordOptions; registering a user name/email that already exists; upgrading ASP.NET Core Identity versions that changed error descriptions; failing lockout checks during login.","solutions":["Inspect identityResult.Errors before calling CheckErrors to see the exact IdentityError codes (DuplicateUserName, PasswordTooShort, etc.) and fix the input data accordingly.","Align your UserManager options (PasswordValidator, UserValidator uniqueness settings) with the data you feed in, or relax them if too strict.","Catch UserFriendlyException in the controller/service layer and map the joined message to your API error response so the user gets actionable feedback.","Localize the messages via the CheckErrors(identityResult, localizationManager) overload (error 171) instead of raw descriptions."],"exampleFix":"// before\nawait _userManager.CreateAsync(user, password);\n\n// after\nvar identityResult = await _userManager.CreateAsync(user, password);\ntry\n{\n    identityResult.CheckErrors();\n}\ncatch (UserFriendlyException e)\n{\n    Logger.Warn(\"User creation failed: \" + e.Message);\n    throw;\n}","handlingStrategy":"try-catch","validationCode":"if (!identityResult.Succeeded)\n{\n    var codes = string.Join(\", \", identityResult.Errors.Select(e => e.Code));\n    Logger.Warn(\"Identity will fail: \" + codes);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    identityResult.CheckErrors();\n}\ncatch (UserFriendlyException e)\n{\n    // e.Message = joined identity error descriptions\n    return BadRequest(new { errors = e.Message });\n}","preventionTips":["Check identityResult.Errors before calling CheckErrors when you need structured codes.","Keep UserManager validation options in sync with your registration UI rules.","Localize messages with the CheckErrors(identityResult, localizationManager) overload.","Handle duplicate user/email up-front with a friendly pre-check where possible."],"tags":["identity","aspnet-core","validation"],"backgroundTag":"schema-validation-failed","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"}