fullstackhero/dotnet-starter-kit · error · CustomException
Update profile failed
Error message
Update profile failed
What it means
UpdateAsync throws CustomException('Update profile failed') when UserManager.UpdateAsync returns a non-succeeded IdentityResult after the profile fields were applied. The identity store rejected the change (e.g. validation or concurrency failure) even though the user was found and the code path reached the save.
Solutions
- Inspect result.Errors (log or surface them) to see the concrete IdentityError descriptions.
- Retry the update if it was a concurrency (ConcurrencyFailure) conflict, re-reading the user first.
- Fix the offending field value (e.g. valid phone number, unique email).
- Check UserManager validator options and any DB unique constraints conflicting with the new values.
Example fix
// before
var result = await userManager.UpdateAsync(user);
if (!result.Succeeded) throw new CustomException("Update profile failed");
// after (caller side: surface identity errors)
if (!result.Succeeded)
{
var desc = string.Join("; ", result.Errors.Select(e => e.Description));
logger.LogWarning("Profile update failed: {Errors}", desc);
throw new CustomException($"Update profile failed: {desc}");
} Defensive patterns
Strategy: try-catch
Validate before calling
if (phoneNumber && !/^\+?[0-9\s().-]{7,20}$/.test(phoneNumber)) throw new Error('Invalid phone number format'); Try / catch
try { await updateProfile(payload); }
catch (e) { if (e.status === 409 || e.status === 400) { await retryWithFreshFetch(); } else { throw e; } } Prevention
- Avoid concurrent profile edits from multiple tabs; reload before editing.
- Validate phone/email fields client-side against identity's rules.
- Log result.Errors server-side to diagnose identity rejections.
- Keep EF concurrency token handling consistent (migrations up to date).
When it happens
Trigger: IdentityResult errors such as ConcurrencyFailure (security stamp/row mismatch), invalid PhoneNumber format, duplicate UserName/Email updates, or store-level constraint violations during profile update.
Common situations: Two tabs/devices saving the profile concurrently (stamp conflict); phone number values failing identity's phone validation; DB constraint issues; custom UserManager validators rejecting the change.
Related errors
- System role permissions are managed by the framework and…
- The authenticator code is invalid.
- UserId must be provided.
- error resetting password
- failed to change password
AI-assisted analysis of fullstackhero/dotnet-starter-kit@3f2959e683 (2026-09-15).
Data as JSON: /api/errors/f2eed19b2563f320.
Report an issue: GitHub.
Appendix: source
Thrown at src/Modules/Identity/Modules.Identity/Services/UserProfileService.cs:115
{
await storageService.RemoveAsync(imageUri.ToString(), cancellationToken);
user.ImageUrl = null;
}
user.FirstName = firstName;
user.LastName = lastName;
string? currentPhoneNumber = await userManager.GetPhoneNumberAsync(user);
if (phoneNumber != currentPhoneNumber)
{
await userManager.SetPhoneNumberAsync(user, phoneNumber);
}
var result = await userManager.UpdateAsync(user);
await signInManager.RefreshSignInAsync(user);
if (!result.Succeeded)
{
throw new CustomException("Update profile failed");
}
}
public async Task SetImageUrlAsync(string userId, string? imageUrl, CancellationToken cancellationToken)
{
EnsureValidTenant();
var user = await userManager.FindByIdAsync(userId)
?? throw new NotFoundException("user not found");
user.ImageUrl = string.IsNullOrWhiteSpace(imageUrl)
? null
: new Uri(imageUrl, UriKind.RelativeOrAbsolute);
var result = await userManager.UpdateAsync(user);
if (!result.Succeeded)
{
throw new CustomException("Update profile image failed");
}View on GitHub (pinned to 3f2959e683)