Michael
Michael

Reputation: 79

FormatException: Input string was not in a correct format. - Changed ASP.net Core Identity PK to int

I've been working on this for the last 3 hours and haven't found a good resource or solution to this problem. I've followed the directions found in Microsoft's documentation to change my ASP.net Privatekey from a string to an int. Since then, I have been presented with the following error:

FormatException: Input string was not in a correct format.

The app will not load past this method in the program.cs class:

    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

I have hit a roadblock and any help with this issue would be appreciated.

Asp.net Error Stack:

FormatException: Input string was not in a correct format. System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)

ArgumentException: 4c3ccce2-61cd-4315-9cf2-99933f6797ed is not a valid value for Int32. (Parameter 'value') System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)

Stack Query Cookies Headers Routing FormatException: Input string was not in a correct format. System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type) int.Parse(string s, NumberStyles style, IFormatProvider provider) System.ComponentModel.Int32Converter.FromString(string value, NumberFormatInfo formatInfo) System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)

Show raw exception details System.FormatException: Input string was not in a correct format. at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type) at System.Int32.Parse(String s, NumberStyles style, IFormatProvider provider) at System.ComponentModel.Int32Converter.FromString(String value, NumberFormatInfo formatInfo) at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) ArgumentException: 4c3ccce2-61cd-4315-9cf2-99933f6797ed is not a valid value for Int32. (Parameter 'value') System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) System.ComponentModel.TypeConverter.ConvertFromInvariantString(string text) Microsoft.AspNetCore.Identity.UserStoreBase<TUser, TKey, TUserClaim, TUserLogin, TUserToken>.ConvertIdFromString(string id) Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<TUser, TRole, TContext, TKey, TUserClaim, TUserRole, TUserLogin, TUserToken, TRoleClaim>.FindByIdAsync(string userId, CancellationToken cancellationToken) Microsoft.AspNetCore.Identity.UserManager.FindByIdAsync(string userId) Microsoft.AspNetCore.Identity.UserManager.GetUserAsync(ClaimsPrincipal principal) Microsoft.AspNetCore.Identity.SignInManager.ValidateSecurityStampAsync(ClaimsPrincipal principal) Microsoft.AspNetCore.Identity.SecurityStampValidator.ValidateAsync(CookieValidatePrincipalContext context) Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler.HandleAuthenticateAsync() Microsoft.AspNetCore.Authentication.AuthenticationHandler.AuthenticateAsync() Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, string scheme) Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Show raw exception details System.ArgumentException: 4c3ccce2-61cd-4315-9cf2-99933f6797ed is not a valid value for Int32. (Parameter 'value') ---> System.FormatException: Input string was not in a correct format. at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type) at System.Int32.Parse(String s, NumberStyles style, IFormatProvider provider) at System.ComponentModel.Int32Converter.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 System.ComponentModel.TypeConverter.ConvertFromInvariantString(String text) at Microsoft.AspNetCore.Identity.UserStoreBase5.ConvertIdFromString(String id) at Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore9.FindByIdAsync(String userId, CancellationToken cancellationToken) at Microsoft.AspNetCore.Identity.UserManager1.FindByIdAsync(String userId) at Microsoft.AspNetCore.Identity.UserManager1.GetUserAsync(ClaimsPrincipal principal) at Microsoft.AspNetCore.Identity.SignInManager1.ValidateSecurityStampAsync(ClaimsPrincipal principal) at Microsoft.AspNetCore.Identity.SecurityStampValidator1.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.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context

Upvotes: 1

Views: 3493

Answers (1)

Yinqiu
Yinqiu

Reputation: 7180

I think the problem may be that the login of your previous user may be completed when the ID is a string.

You now change it to int, so now it no longer knows what to do with the string.

I think the simplest solution is that you should delete the cookie, log out and log in again (use int instead).

Upvotes: 3

Related Questions