We are upgrading a client's web app from .NET 4.6 to .Net 6. The old system uses Identity 2 and EF 6. Both systems need to coexist for an indefinite period of time. At first we could not log in from the new system without it overwriting the passwords in the old system, making them unusable. We fixed that with:
services.Configure<PasswordHasherOptions>(option => option.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2);
Then we followed the path outlined this StackOverflow article which had scripts to update the SQL tables and tells us how to include the Microsoft.AspNet.Identity.CoreCompat library. However, it seems to not work when it comes to the LockoutEnd field in the AspNetUsers table. The scripts leave this field as a datetime2 field. However, when running in .NET 6, we get the error:
System.InvalidCastException: Unable to cast object of type 'System.DateTime' to type 'System.DateTimeOffset'.
Changing the field in SQL to a DateTimeOffset(7) allows Identity .NET 6 to work, but breaks Identity 2 because it expects type DateTime and got DateTimeOffset. If the field is null, it works no problem. However, if there was a date in the field, anything accessing the user, like FindByNameAsync will throw the error.
There must be a way for this to work. I can't imagine we are the only ones having this problem. I have no idea how this could have slipped by everyone else.
Does anyone have a solution to this? Is there some other config setting I am missing?