I’ve changed the Identity user key from a GUID to an int in a .NET Core APIs application. Since making this change, every API call returns the following error:
{
"Code": 500,
"Message": "331b9a42-6807-46ca-97ee-7c9bbe518ef7 is not a valid value for Int64. (Parameter 'value')"
}
Despite following the setup steps, the issue persists. Here is the current setup:
public class BrokerDbContext : IdentityDbContext<ApplicationUser, IdentityRole<long>, long>
public class ApplicationUser : IdentityUser<long>, ICreationDateAuditedEntity, IModificationDateAuditedEntity, IStripeEntity
builder.Services.AddIdentity<ApplicationUser, IdentityRole<long>>()
.AddEntityFrameworkStores<BrokerWiseDbContext>()
.AddDefaultTokenProviders();
However, it seems the system is still trying to process GUIDs, resulting in the error.
full error:
[18:13:11 ERR] An unhandled exception has occurred while executing the request.
System.ArgumentException: 331b9a42-6807-46ca-97ee-7c9bbe518ef7 is not a valid value for Int64. (Parameter 'value')
---> System.FormatException: The input string '331b9a42-6807-46ca-97ee-7c9bbe518ef7' was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, ReadOnlySpan`1 value, TypeCode type)
at System.Int64.Parse(String s, NumberStyles style, IFormatProvider provider)
at System.ComponentModel.Int64Converter.FromString(String value, NumberFormatInfo formatInfo)
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
--- End of inner exception stack trace ---
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at Microsoft.AspNetCore.Identity.UserStoreBase`5.ConvertIdFromString(String id)
at Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9.FindByIdAsync(String userId, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Identity.UserManager`1.GetUserAsync(ClaimsPrincipal principal)
at Microsoft.AspNetCore.Identity.SignInManager`1.ValidateSecurityStampAsync(ClaimsPrincipal principal)
at Microsoft.AspNetCore.Identity.SecurityStampValidator`1.ValidateAsync(CookieValidatePrincipalContext context)
at Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
and changes are reflected in the DB.
4