aspnetboilerplate/aspnetboilerplate · error · UserFriendlyException

identityResult.Errors (joined with ", ")

Error message

identityResult.Errors (joined with ", ")

What it means

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.

Solutions

  1. Inspect identityResult.Errors before calling CheckErrors to see the exact IdentityError codes (DuplicateUserName, PasswordTooShort, etc.) and fix the input data accordingly.
  2. Align your UserManager options (PasswordValidator, UserValidator uniqueness settings) with the data you feed in, or relax them if too strict.
  3. Catch UserFriendlyException in the controller/service layer and map the joined message to your API error response so the user gets actionable feedback.
  4. Localize the messages via the CheckErrors(identityResult, localizationManager) overload (error 171) instead of raw descriptions.

Example fix

// before
await _userManager.CreateAsync(user, password);

// after
var identityResult = await _userManager.CreateAsync(user, password);
try
{
    identityResult.CheckErrors();
}
catch (UserFriendlyException e)
{
    Logger.Warn("User creation failed: " + e.Message);
    throw;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!identityResult.Succeeded)
{
    var codes = string.Join(", ", identityResult.Errors.Select(e => e.Code));
    Logger.Warn("Identity will fail: " + codes);
}

Try / catch

try
{
    identityResult.CheckErrors();
}
catch (UserFriendlyException e)
{
    // e.Message = joined identity error descriptions
    return BadRequest(new { errors = e.Message });
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of aspnetboilerplate/aspnetboilerplate@2323c13a15 (2026-09-08). Data as JSON: /api/errors/84c0ed30ddc3699b. Report an issue: GitHub.

Appendix: source

Thrown at src/Abp.ZeroCore/IdentityFramework/IdentityResultExtensions.cs:57

                  {"User already in role '{0}'.", "Identity.UserAlreadyInRole"},
                  {"User is locked out.", "Identity.UserLockedOut"},
                  {"Lockout is not enabled for this user.", "Identity.UserLockoutNotEnabled"},
                  {"User {0} does not exist.", "Identity.UserNameNotFound"},
                  {"User is not in role '{0}'.", "Identity.UserNotInRole"}
          };

    /// <summary>
    /// Checks errors of given <see cref="IdentityResult"/> and throws <see cref="UserFriendlyException"/> if it's not succeeded.
    /// </summary>
    /// <param name="identityResult">Identity result to check</param>
    public static void CheckErrors(this IdentityResult identityResult)
    {
        if (identityResult.Succeeded)
        {
            return;
        }

        throw new UserFriendlyException(identityResult.Errors.Select(err => err.Description).JoinAsString(", "));
    }

    /// <summary>
    /// Checks errors of given <see cref="IdentityResult"/> and throws <see cref="UserFriendlyException"/> if it's not succeeded.
    /// </summary>
    /// <param name="identityResult">Identity result to check</param>
    /// <param name="localizationManager">Localization manager to localize error messages</param>
    public static void CheckErrors(this IdentityResult identityResult, ILocalizationManager localizationManager)
    {
        if (identityResult.Succeeded)
        {
            return;
        }

        throw new UserFriendlyException(identityResult.LocalizeErrors(localizationManager));
    }

    public static string LocalizeErrors(this IdentityResult identityResult, ILocalizationManager localizationManager)

View on GitHub (pinned to 2323c13a15)