Why does this violate the type constraint?

徘徊边缘 提交于 2019-11-27 21:58:17

Ran into this problem. It was crashing on the startup.cs file. changed

services.AddIdentity<ApplicationUser, ApplicationIdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

to

services.AddIdentity<ApplicationUser, ApplicationIdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext,int>()
                .AddDefaultTokenProviders();

declaring the key type seemed to get past the crash

Ran into this problem as well. I had to add IdentityRole key type also, because it was still throwing the same error.

        services.AddIdentity<ApplicationUser, IdentityRole<int>>()
            .AddEntityFrameworkStores<ApplicationDbContext,int>()
            .AddDefaultTokenProviders();

I got the same problem now. Fix was different. Hence posting it here. Might help others.

    services.AddIdentity<ApplicationUser, ApplicationRole>()
        .AddEntityFrameworkStores<ApplicationDbContext,int>()
        .AddDefaultTokenProviders();

I had to create an empty class for ApplicationRole inheriting IdentityRole<int>.

public class ApplicationRole : IdentityRole<int> 
{

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!