fullstackhero/dotnet-starter-kit · error · CustomException

Update profile image failed

Error message

Update profile image failed

What it means

SetImageUrlAsync throws CustomException('Update profile image failed') when UserManager.UpdateAsync returns a failed IdentityResult while persisting the new ImageUrl. The user was found and the URI assigned, but the identity store refused the save.

Solutions

  1. Log result.Errors to identify the exact IdentityError(s).
  2. Retry after re-fetching the user if it was a ConcurrencyFailure.
  3. Validate the image URL format/length before calling the API.
  4. Check UserManager validators and database constraints against the new ImageUrl value.
Defensive patterns

Strategy: try-catch

Validate before calling

let parsed; try { parsed = new URL(imageUrl); } catch { throw new Error('Image URL is not a valid URI'); }
if (imageUrl.length > 2048) throw new Error('Image URL too long');

Try / catch

try { await setProfileImage(url); }
catch (e) { if (e.status === 409 || e.status === 400) { await refetchUserAndRetry(); } else { throw e; } }

Prevention

When it happens

Trigger: Concurrency stamp mismatch on the user row, store/constraint failures, or a custom user validator rejecting the modified entity during image URL update.

Common situations: Concurrent profile edits from multiple sessions; DB unique/constraint issues; malformed or overly long URL values rejected by validators; migration drift causing store errors.

Related errors


AI-assisted analysis of fullstackhero/dotnet-starter-kit@3f2959e683 (2026-09-15). Data as JSON: /api/errors/1190dfed88deb59e. Report an issue: GitHub.

Appendix: source

Thrown at src/Modules/Identity/Modules.Identity/Services/UserProfileService.cs:132

        {
            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");
        }

        await signInManager.RefreshSignInAsync(user);
    }

    public async Task<bool> ExistsWithEmailAsync(string email, string? exceptId = null, CancellationToken cancellationToken = default)
    {
        EnsureValidTenant();
        return await userManager.FindByEmailAsync(email.Normalize()) is FshUser user && user.Id != exceptId;
    }

    public async Task<bool> ExistsWithNameAsync(string name, CancellationToken cancellationToken = default)
    {
        EnsureValidTenant();
        return await userManager.FindByNameAsync(name) is not null;
    }

    public async Task<bool> ExistsWithPhoneNumberAsync(string phoneNumber, string? exceptId = null, CancellationToken cancellationToken = default)

View on GitHub (pinned to 3f2959e683)