fullstackhero/dotnet-starter-kit · error · CustomException
An error occurred while confirming the email for
Error message
An error occurred while confirming the email for {0}: {1} What it means
Thrown as a CustomException when userManager.UpdateAsync fails after setting EmailConfirmed = true, meaning ASP.NET Identity persistence rejected the change. The message embeds the user's email and all Identity error descriptions (e.g. concurrency stamp conflict, validation failures). It indicates the confirm operation could not be saved to the database.
Solutions
- Read the appended error descriptions in the message for the root Identity error
- Retry once if the description indicates a concurrency stamp conflict (re-fetch user then confirm again)
- Check database connectivity/migration state if descriptions indicate a store failure
- Review any custom IUserValidator rules that might fail on save
Example fix
// before
await userRegistrationService.AdminConfirmEmailAsync(userId, ct);
// after
try
{
await userRegistrationService.AdminConfirmEmailAsync(userId, ct);
}
catch (CustomException ex)
{
logger.LogWarning(ex, "Email confirm failed: {Errors}", ex.Errors);
// surface result.ErrorDescriptions to the caller
} Defensive patterns
Strategy: try-catch
Validate before calling
var user = await userManager.Users.AsNoTracking().FirstOrDefaultAsync(u => u.Id == userId); if (user is null || user.EmailConfirmed) return;
Type guard
if (!result.Succeeded) return Results.Conflict(result.Errors.Select(e => e.Description));
Try / catch
catch (CustomException ex) { logger.LogWarning("Confirm failed: {Errors}", string.Join(";", ex.Errors ?? [])); return Results.Conflict(ex.Errors); } Prevention
- Minimize the window between loading and updating the user to avoid concurrency conflicts
- Surface result.ErrorDescriptions to clients instead of a generic retry loop
- Check DB health/migrations when this appears across many users
When it happens
Trigger: userManager.UpdateAsync returns a failed IdentityResult during AdminConfirmEmailAsync — e.g. concurrency stamp mismatch (user edited concurrently), store/provider errors, or user validation failures on save.
Common situations: Two admins confirming at once → concurrency stamp conflict; security stamp changed by a password reset mid-request; database connectivity issues; custom user validator rejecting the entity state.
Related errors
- Failed to generate authenticator key.
- Failed to create user from external principal.
- Toggle status failed
- Group with ID ' ' not found.
- Users not found
AI-assisted analysis of fullstackhero/dotnet-starter-kit@3f2959e683 (2026-09-15).
Data as JSON: /api/errors/f92584d1504f0336.
Report an issue: GitHub.
Appendix: source
Thrown at src/Modules/Identity/Modules.Identity/Services/UserRegistrationService.cs:111
{
EnsureValidTenant();
var user = await userManager.Users
.Where(u => u.Id == userId)
.FirstOrDefaultAsync(cancellationToken)
?? throw new NotFoundException($"User {userId} was not found.");
// Idempotent: a second confirm is a no-op rather than an error.
if (user.EmailConfirmed)
{
return;
}
user.EmailConfirmed = true;
var result = await userManager.UpdateAsync(user);
if (!result.Succeeded)
{
throw new CustomException(string.Format(
CultureInfo.InvariantCulture,
"An error occurred while confirming the email for {0}: {1}",
user.Email,
string.Join("; ", result.Errors.Select(e => e.Description))));
}
}
public async Task ResendConfirmationEmailAsync(string userId, string origin, CancellationToken cancellationToken = default)
{
EnsureValidTenant();
var user = await userManager.Users
.Where(u => u.Id == userId)
.FirstOrDefaultAsync(cancellationToken)
?? throw new NotFoundException($"User {userId} was not found.");
if (user.EmailConfirmed)
{View on GitHub (pinned to 3f2959e683)