Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
karandesai28 opened this issue Nov 15, 2017 · 1 comment

Comments

@karandesai28
Copy link

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.

@mrahhal
Copy link
Owner

mrahhal commented Nov 15, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants