{"record":{"id":"1190dfed88deb59e","repo":"fullstackhero/dotnet-starter-kit","slug":"update-profile-image-failed","errorCode":null,"errorMessage":"Update profile image failed","messagePattern":"Update profile image failed","errorType":"exception","errorClass":"CustomException","httpStatus":400,"severity":"error","filePath":"src/Modules/Identity/Modules.Identity/Services/UserProfileService.cs","lineNumber":132,"sourceCode":"        {\n            throw new CustomException(\"Update profile failed\");\n        }\n    }\n\n    public async Task SetImageUrlAsync(string userId, string? imageUrl, CancellationToken cancellationToken)\n    {\n        EnsureValidTenant();\n        var user = await userManager.FindByIdAsync(userId)\n            ?? throw new NotFoundException(\"user not found\");\n\n        user.ImageUrl = string.IsNullOrWhiteSpace(imageUrl)\n            ? null\n            : new Uri(imageUrl, UriKind.RelativeOrAbsolute);\n\n        var result = await userManager.UpdateAsync(user);\n        if (!result.Succeeded)\n        {\n            throw new CustomException(\"Update profile image failed\");\n        }\n\n        await signInManager.RefreshSignInAsync(user);\n    }\n\n    public async Task<bool> ExistsWithEmailAsync(string email, string? exceptId = null, CancellationToken cancellationToken = default)\n    {\n        EnsureValidTenant();\n        return await userManager.FindByEmailAsync(email.Normalize()) is FshUser user && user.Id != exceptId;\n    }\n\n    public async Task<bool> ExistsWithNameAsync(string name, CancellationToken cancellationToken = default)\n    {\n        EnsureValidTenant();\n        return await userManager.FindByNameAsync(name) is not null;\n    }\n\n    public async Task<bool> ExistsWithPhoneNumberAsync(string phoneNumber, string? exceptId = null, CancellationToken cancellationToken = default)","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/fullstackhero/dotnet-starter-kit/blob/3f2959e683e9f83f13e55e1678c9119f63c7e8e5/src/Modules/Identity/Modules.Identity/Services/UserProfileService.cs#L114-L150","documentation":"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.","triggerScenarios":"Concurrency stamp mismatch on the user row, store/constraint failures, or a custom user validator rejecting the modified entity during image URL update.","commonSituations":"Concurrent profile edits from multiple sessions; DB unique/constraint issues; malformed or overly long URL values rejected by validators; migration drift causing store errors.","solutions":["Log result.Errors to identify the exact IdentityError(s).","Retry after re-fetching the user if it was a ConcurrencyFailure.","Validate the image URL format/length before calling the API.","Check UserManager validators and database constraints against the new ImageUrl value."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"let parsed; try { parsed = new URL(imageUrl); } catch { throw new Error('Image URL is not a valid URI'); }\nif (imageUrl.length > 2048) throw new Error('Image URL too long');","typeGuard":null,"tryCatchPattern":"try { await setProfileImage(url); }\ncatch (e) { if (e.status === 409 || e.status === 400) { await refetchUserAndRetry(); } else { throw e; } }","preventionTips":["Validate URL format and length before submission.","Serialize profile image updates (disable double-submit).","Check server logs for IdentityError details on failures.","Keep database migrations and identity store schema in sync."],"tags":["identity","update","image"],"backgroundTag":"database-write-failed","analyzedSha":"3f2959e683e9f83f13e55e1678c9119f63c7e8e5","analyzedAt":"2026-09-15T22:20:53.684Z","contentChangedAt":"2026-09-15T22:20:53.684Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}