MR.AspNet.Identity.EntityFramework6 icon indicating copy to clipboard operation
MR.AspNet.Identity.EntityFramework6 copied to clipboard

Sample or concise documentation for setting up User Store- Getting TypeLoadException while setting up User Store

Open karandesai28 opened this issue 8 years ago • 1 comments

I am facing difficulty in setting up User Store using this library. There is no sample or usage guide that clearly showcase how to setup user store. My code is as follows:

ApplicationUser.cs

public class ApplicationUser : IdentityUser<int,ApplicationUserLogin,ApplicationUserRole,ApplicationUserClaim>, IEntity<int>
    {
   }

ApplicationRole.cs

public class ApplicationRole : IdentityRole<int,ApplicationUserRole,IdentityRoleClaim<int>>, IEntity<int>
    {
      

    }

ApplicationUserRole, ApplicationUserLogin,ApplicationUserClaim classes

 public class ApplicationUserRole : IdentityUserRole<int> { }
    public class ApplicationUserClaim : IdentityUserClaim<int> { }
    public class ApplicationUserLogin : IdentityUserLogin<int> { }

MyDbContext.cs

public class MyDbContext: IdentityDbContext<ApplicationUser, ApplicationRole,int,ApplicationUserLogin,ApplicationUserRole,ApplicationUserClaim,IdentityRoleClaim<int>>
    {


        public MyDbContext(string connectionString):base(connectionString)
        {

        }
}

and UserStore is this:

public class ApplicationUserStore : UserStore<ApplicationUser,ApplicationRole,ApplicationUserRole,ApplicationUserClaim,ApplicationUserLogin,IdentityRoleClaim<int>,MyDbContext,int>
    {
        public ApplicationUserStore(MyDbContext context) : base(context)
        {

        }
    }

I am getting following run time exception:

System.ArgumentException: GenericArguments[0], 'ApplicationUser', on 'MR.AspNet.Identity.EntityFramework6.UserStore3[TUser,TRole,TContext]' violates the constraint of type 'TUser'. ---> System.TypeLoadException: GenericArguments[0], ApplicationUser', on 'MR.AspNet.Identity.EntityFramework6.UserStore8[TUser,TRole,TUserRole,TUserClaim,TUserLogin,TRoleClaim,TContext,TKey]' violates the constraint of type parameter 'TUser'.

What is going on here, and what am I doing wrong? Any samples, usage guide or solution appreciated?

Please note I have also tried this using int package i.e I have also tried using IdentityUserInt, IdentityRoleInt etc, but same exception.

karandesai28 avatar Nov 15 '17 04:11 karandesai28

The reason there's no usage guide is that I depend on Identity's docs. I did my best to do everything similar to their own structure. Identity has some really complex generic usage, so it's not unexpected to face problems when you're doing your own impl.

I can help in pointing out what the error is if you publish a small repro of this. From just looking at it, I could't catch anything.

mrahhal avatar Nov 15 '17 05:11 mrahhal