Message:
\"System.NotSupportedException was unhandled
Message: An unhandled exception of type \'System.NotSupportedException\' occurred in mscor
Here's your problem:
userLangs.ForEach(async
This is creating an async void
method, because ForEach
does not understand asynchronous delegates. So the body of the ForEach
will be run concurrently, and Entity Framework does not support concurrent asynchronous access.
Change the ForEach
to a foreach
, and you should be good:
foreach (var l in userLangs)
{
var userLanguage = new UserLang();
userLanguage.UserId = userId;
userLanguage.LanguageId = await ...
}
For more information, see the "avoid async void" guidance in my Async Best Practices article.