ASP Core violates the constraint of type parameter 'TRole' for String

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

Question

I'm trying to use openiddict and EF 7 in my ASP Core RC2 site. When I try to create a migration using dotnet ef migrations add <name> I get the following error:

System.ArgumentException: GenericArguments[1], 'System.String', on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`3[TUser,TRole,TContext]' violates the constraint of type 'TRole'. ---> System.TypeLoadException: GenericArguments[1], 'System.String', on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`4[TUser,TRole,TContext,TKey]' violates the constraint of type parameter 'TRole'.
at System.RuntimeTypeHandle.Instantiate(RuntimeTypeHandle handle, IntPtr* pInst, Int32 numGenericArgs, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.Instantiate(Type[] inst)

In my Startup.cs I have the following:

        services.AddIdentity<MyUser, string>()
            .AddEntityFrameworkStores<MyContext>()
            .AddDefaultTokenProviders()
            .AddOpenIddict();

My User and context are defined like this:

         public class MyUser : IdentityUser
         {
         }
         public class MyContext : OpenIddictContext<MyUser>
         {
         }

I think the error has something to do with the fact that I said to use string string for TRole. Is this not allowed? What types are supported for TRole?

1
1
6/1/2016 12:38:59 AM

Popular Answer

I think the error has something to do with the fact that I said to use string string for TRole. Is this not allowed? What types are supported for TRole?

Nope, it's not. When using the default Entity Framework stores for ASP.NET Core Identity, your role entity must inherit from IdentityRole.

2
6/1/2016 12:43:37 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow