My situation is different: I was trying to seed the database with 30 users, belonging to specific roles, so I was running this code:
for (var i = 1; i <= 30; i++)
{
CreateUserWithRole("Analyst", $"analyst{i}", UserManager);
}
This was a Sync function. Inside of it I had 3 calls to:
UserManager.FindByNameAsync(username).Result
UserManager.CreateAsync(user, pass).Result
UserManager.AddToRoleAsync(user, roleName).Result
When I replaced .Result
with .GetAwaiter().GetResult()
, this error went away.