NedTheNerd
NedTheNerd

Reputation: 1

.NET 6 Identity Customization - Error: There is no implicit reference conversion from ApplicationUser to IdentityUser<string>

I have customized all .NET 6 Identity model classes. My setup was working just fine for over a year. I updated to the latest .NET core identity libraries (6.0.7) and ran a new DB-Scaffold today, and all of a sudden, I'm getting the following error for ApplicationUser (plus the same error for the remainder of the custom Identity classes):

CS0311 The type 'ApplicationUser' cannot be used as type parameter 'TUser' in the generic type or method 'IdentityDbContext<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken>'. There is no implicit reference conversion from 'ApplicationUser' to 'Microsoft.AspNetCore.Identity.IdentityUser'

I've got the EF database context configured as follows:

public partial class DatabaseContext : IdentityDbContext<ApplicationUser, ApplicationRole, string, ApplicationUserClaim, ApplicationUserRole, ApplicationUserLogin, ApplicationRoleClaim, ApplicationUserToken>

My Identity classes are as follows:

public partial class ApplicationUser : IdentityUser<string>

public partial class ApplicationRole : IdentityRole<string>

public partial class ApplicationUserClaim : IdentityUserClaim<string>

public partial class ApplicationUserRole : IdentityUserRole<string>

public partial class ApplicationUserLogin : IdentityUserLogin<string>

public partial class ApplicationRoleClaim : IdentityRoleClaim<string>

public partial class ApplicationUserToken : IdentityUserToken<string>

This approach seems to be lined up with what Microsoft recommends here: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?view=aspnetcore-6.0

I've tried everything I can think of but the errors are still coming up (tried changing over to a Guid instead of a string, for example). I'm at a loss and hoping someone might be able to give me some advice on how to fix these errors?

Upvotes: 0

Views: 637

Answers (1)

NedTheNerd
NedTheNerd

Reputation: 1

This was due to the fact that I was still configured for the .NET 5 way of using Identity. I created a new .NET 6 MVC project and migrated everything over to it, and that fixed the problem.

Upvotes: 0

Related Questions