Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input string was not in a correct format - wrong context is used

After changing ASP.NET Core Identity to use int rather than GUID (as per this blog post) I am receiving the following error:

ArgumentException: 395438ed-1cd9-4420-8a58-3f3b1f550bfc is not a valid value for Int32. Parameter name: value System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) Microsoft.AspNetCore.Identity.UserStoreBase.ConvertIdFromString(string id) Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore.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.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

when trying to query the database. Any clues as to why that might be?

like image 702
JeyJ Avatar asked Oct 11 '19 12:10

JeyJ


People also ask

Why is the input string was not in a correct format?

The input string was not in a correct format error might occur when you try to convert a non-numeric string from the input into an int. Moreover, you’ll get the said error while storing the input values that are larger than the range of the int data type as int.

What is an ‘input’ string?

An ‘input’ string refers to the data passed to a computer through a peripheral device such as a keyboard. A good example of this can be the data that you fill in the text boxes of an online form. – How To Ensure That the ‘Input’ String Matches a Particular Format?

When form initializes text box may not have a value?

When form initializes text box may not hae value if you have not put it in textbox when during form design. you can put int value in form design by setting text property in desgin and this should work. Share Follow answered Nov 30 '11 at 5:29

Why do I get error when converting non-numeric data to INT?

The given error occurs when you attempt to convert non-numeric data into an int. Also, exceeding the limit of the int data type to store larger values will give you the same error. Here are the detailed explanations of the causes: Are you working on a Windows Form and getting the above error?


1 Answers

As per one of the comments in the blog post:

Thank you, this article was really useful. One gotcha for me was that after swapping to use an int when I first loaded identity server again I got an error on this line

Microsoft.AspNetCore.Identity.UserStoreBase.ConvertIdFromString(string id).

Turns out I had a cookie using the old guid format, simple fix was to clear cookies.

The issue is that some of your previous logins were likely done when the ID was a GUID. You changed it to int, and so now it doesn't know how to handle the GUID any more. The simplest solution will be to delete your cookies, effectively logging you out and forcing you to login again (using int instead).

like image 151
mjwills Avatar answered Nov 02 '22 23:11

mjwills