title: Why this violates the constraint of type parameter 'TUser'?
body: <p>I am trying to customize asp.net identity entities with the following ones:</p>
  
  <pre><code>public class User : IdentityUser&lt;string, UserClaim, UserRole, UserLogin&gt;
  public class UserClaim : IdentityUserClaim&lt;string&gt;
  public class UserLogin : IdentityUserLogin&lt;string&gt;
  public class UserRole : IdentityUserRole&lt;string&gt;
  public class UserToken : IdentityUserToken&lt;string&gt;
  public class Role : IdentityRole&lt;string, UserRole, RoleClaim&gt;
  public class RoleClaim : IdentityRoleClaim&lt;string&gt;
  </code></pre>
  
  <p>I have then created a DbContext class like the following </p>
  
  <pre><code>public class AppDbContext : IdentityDbContext&lt;User, Role, string, UserClaim, UserRole, UserLogin, RoleClaim, UserToken&gt;
  </code></pre>
  
  <p>And then configure these with </p>
  
  <pre><code>services
      .AddIdentity&lt;User, Role&gt;()
      .AddEntityFrameworkStores&lt;AppDbContext&gt;()
      .AddDefaultTokenProviders();
  </code></pre>
  
  <p>but I have tried also with </p>
  
  <pre><code>.AddEntityFrameworkStores&lt;AppDbContext, string&gt;()
  </code></pre>
  
  <p>I have read many blog posts on the internet, like <a href="https://stackoverflow.com/questions/30018109/why-does-this-violate-the-type-constraint">this</a> for example, but most of them have to deal against a change of data type for the keys, like to <code>int</code> or <code>Guid</code>. In my case I am not changing the default key datatype from <code>string</code>.</p>
  
  <p>I all these cases the compile is ok but it throws an error when running </p>
  
  <blockquote>
    <p>System.TypeLoadException 
    GenericArguments[0],'MyIdentity.Entities.User', on
    'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`8[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken]'
    violates the constraint of type parameter 'TUser'.</p>
    
    <p>at System.RuntimeTypeHandle.Instantiate(RuntimeTypeHandle handle,
    IntPtr* pInst, int numGenericArgs, ObjectHandleOnStack type) at
    System.RuntimeTypeHandle.Instantiate(Type[] inst) at
    System.RuntimeType.MakeGenericType(Type[] instantiation)</p>
  </blockquote>
  
  <p>If I add a customized <code>UserStore</code> class like explained in <a href="https://stackoverflow.com/questions/38179694/aspnetcore-identity-not-working-with-custom-user-role-implementation">this post</a></p>
  
  <pre><code>public class UserStore : UserStore&lt;User, Role, AppDbContext, string, UserClaim, UserRole, UserLogin, UserToken&gt;
  </code></pre>
  
  <p>A compile error appear saying that </p>
  
  <blockquote>
    <p>CS0311    The type 'MyIdentity.Entities.Role' cannot be used as type
    parameter 'TRole' in the generic type or method 'UserStore'. There is no implicit reference conversion from
    'MyIdentity.Entities.Role' to
    'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole>'</p>
  </blockquote>
  
  <p>What I am doing wrong?</p>