There is no implicit reference conversion from ApplicationUser to IdentityUser

asp.net-identity c# entity-framework-6 entity-framework-core generics

Question

I am trying to customize some ASP.NET Identity Core classes which use Generics.

My ApplicationUser class:

public class ApplicationUser : IdentityUser<Guid>//, ApplicationUserClaim, ApplicationRole, ApplicationUserLogin> 
{
    public ApplicationUser() {  }
}

My ApplicationUserStore class:

public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, ApplicationDbContext, Guid> 
{
    public ApplicationUserStore(ApplicationDbContext ctx, IdentityErrorDescriber describer = null) : base(ctx, describer)
    {

    }
}

Error message is:

'AspDotNetCoreFullFramework.Identity.ApplicationUser1[System.Guid]', onMicrosoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`8[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken]' violates the constraint of type parameter 'TUser'

Now, when I go to the .NET implementation of UserStore (Base class):

public class UserStore<TUser, TRole, TContext, TKey> : UserStore<TUser, TRole, TContext, TKey, IdentityUserClaim<TKey>, IdentityUserRole<TKey>, IdentityUserLogin<TKey>, IdentityUserToken<TKey>>
where TUser : IdentityUser<TKey>
... where TKey : IEquatable<TKey> {

I can see that ApplicationUser inherits from IdentityUser<GUID>. This constraint is fulfilled. TKey is GUID which implements IEquatable<GUID>. This constraint is also fulfilled.

So what is the problem?

Accepted Answer

Adding the GUID to

IdentityBuilder.AddEntityFrameworkStores<ApplicationDbContext,Guid>();

as mentioned in this post solved the problem.



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why