'Irregular error "The specified cast is not valid" at UserManager.FindByNameAsync(model.Email)

I am using the code:

ApplicationUser user = await UserManager.FindByNameAsync(model.Email);

to authenticate user on login in ASP.NET MVC application. Framework 4.7.2.

I am getting an error:

The specified cast from a materialized 'System.String' type to the 'System.Int32' type is not valid.

The error is irregular. Most of the time this code works. A few times per day it gives an error and the website stops working until restarted or until I re-deploy the source.

I tried using:

ApplicationUser user = UserManager.FindByName(model.Email); and ApplicationUser user = await UserManager.FindByNameAsync(model.Email);

with the same result.

I am hosting it at GoDaddy via Plesk. I have no access to the Microsoft library and I am about to start re-coding it for a luck of better solutions.

Please advise :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source