2
votes

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?

1
Or point me to a reference regarding this problem..Legends
what it exactly you are trying to do in regards to Identity, can you explain that a little bit more in detail.. I think this may help others point you into taking a different approach..MethodMan
I just want to implement the ASP.NET Identity API as customizable as possible, in order to have it available as an template for future projects. Later I can have a look at it, without much exploration effort.Legends

1 Answers

2
votes

Adding the GUID to

IdentityBuilder.AddEntityFrameworkStores<ApplicationDbContext,Guid>();

as mentioned in this post solved the problem.