2.1.0-rc1-final version throws Cannot create a DbSet for 'IdentityUserClaim<string>' because this type is not included in the model for the context exeption on SignInManager<TUser>.PasswordSignInAsync:
Microsoft.EntityFrameworkCore.Internal.InternalDbSet<TEntity>.get_EntityType()
Microsoft.EntityFrameworkCore.Internal.InternalDbSet<TEntity>.get_EntityQueryable()
Microsoft.EntityFrameworkCore.Internal.InternalDbSet<TEntity>.System.Linq.IQueryable.get_Provider()
System.Linq.Queryable.Where<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<TUser, TRole, TContext, TKey, TUserClaim, TUserRole, TUserLogin, TUserToken, TRoleClaim>.GetClaimsAsync(TUser user, CancellationToken cancellationToken)
Microsoft.AspNetCore.Identity.UserManager<TUser>.GetClaimsAsync(TUser user)
Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory<TUser>.GenerateClaimsAsync(TUser user)
Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory<TUser, TRole>.GenerateClaimsAsync(TUser user)
Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory<TUser>.CreateAsync(TUser user)
Microsoft.AspNetCore.Identity.SignInManager<TUser>.CreateUserPrincipalAsync(TUser user)
Microsoft.AspNetCore.Identity.SignInManager<TUser>.SignInAsync(TUser user, AuthenticationProperties authenticationProperties, string authenticationMethod)
Microsoft.AspNetCore.Identity.SignInManager<TUser>.SignInOrTwoFactorAsync(TUser user, bool isPersistent, string loginProvider, bool bypassTwoFactor)
Microsoft.AspNetCore.Identity.SignInManager<TUser>.PasswordSignInAsync(TUser user, string password, bool isPersistent, bool lockoutOnFailure)
Microsoft.AspNetCore.Identity.SignInManager<TUser>.PasswordSignInAsync(string userName, string password, bool isPersistent, bool lockoutOnFailure)
Project.Controllers.AccountController.Login(LoginViewModel model, string returnUrl) in AccountController.cs
+ var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false);
Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Issue does not occur on Windows, but occurs on Linux (both using Kestrel), downgrading to current stable version solves the issue.
Failing:
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0-rc1-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0-rc1-final" />
Passing:
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.3" />
@ajcvickers
@ajcvickers I'm seeing a similar error message with IdentityUserClaim<Guid>. It can be mitigated by adding
```c#
public DbSet
To the db context. Shouldn't
```c#
services.AddIdentity<IdentityUser<Guid>, IdentityRole<Guid>>()
.AddEntityFrameworkStores<MyDbContext>();
add all the identity DbSets by itself?
I'm really new to Asp.Net Core. I face the same issue:
InvalidOperationException: Cannot create a DbSet for 'IdentityUserClaim<**string**>
because this type is not included in the model for the context.
So, based on what @myrup mentioned I was able to sort out the exception, even though I'm not quite sure why I needed to perform all this.
In my case I had a custom User inheriting from "IdentityUser"
public class ForeCastUser : IdentityUser
{
So, in my Context I had to add the following:
public class ForeCastContext : DbContext
{
...
public DbSet<IdentityUserClaim<string>> IdentityUserClaim { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{ modelBuilder.Entity<IdentityUserClaim<string>>().HasKey(p => new { p.Id });
}
I hope this could help others.
I will appreciate any insight or clarification on this.
I'm still wondering about this. Also I'm getting a primary key duplicate error on await userManager.AddClaimsAsync(user, newClaims) because there seems to be a bug handling the auto incrementing integer specified by IdentityUserClaim<TKey> (And why can't this be changed from integer like the Primary key TKey of Identity users)?
Update: I'm using Npgsql, to alleviate the duplicate primary key I had to add:
c#
modelBuilder.Entity<IdentityUserClaim<Guid>>().Property("Id").UseNpgsqlSerialColumn();
I had the same issue.
However the solution for me was that I was trying to sign in right after signing up using
SignInAsync(..) and I passed in the entire User model rather than using PasswordSignInAsync(User.UserName, User.Password, false, false).
Iirc in ASP.NET Core 1.0 you would use SignInAsync(...) but I am now using 3.0.
If you are using a DbContext not derived.from IdentityDbContext, then you could see this error as per #12511
Most helpful comment
If you are using a DbContext not derived.from IdentityDbContext, then you could see this error as per #12511