Im able to create roles using role manager and add user to a role using UserManager.AddToRoleAsync But when using method UserManager.RemoveFromRoleAsync(User, Role), im always getting error saying UserNotInRole
But when using UserManager.GetUsersInRoleAsync("Administrator"), I'm getting results.
But again method UserManager.IsInRoleAsync(user, "Administrator"); return false.
Next, upon checking on the SQL profiler, I noticed that parameters set for userId & roleid is opposite during select statement of UserInRole table
Any idea what is causing this weird behaviour? Im using Identity.Core, Version=3.1.3.0
Updated the code snippet
My AspNetUserole Table
Refer to below image, only methods IsInRoleAsync & RemoveFromRoleAsync get fails, other methods are getting results.
Looks like your keys for the identity UserRole table is configured wrongly. Can post the code snippet where you have modified the IdentityUserRole table?
It should be like following configuration
builder.Entity<IdentityUserRole<int>>().ToTable("Rmit.UserRole").HasKey(k => new { k.UserId,k.RoleId });