I am using MVC5 + Entity Framework and I am getting an strange exception.The exception seems to be due to a concurrency problem when multiple users are using the site at the same time. The exception says:
System.NotSupportedExceptionA second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. Any instance members are not guaranteed to be thread safe.
Now based on the logs, the culprit is the following method:
public async Task<Customer> GetUserByUserIdAsync(string userId)
{
return await DbContext.Users.FirstOrDefaultAsync(u => u.Id == userId);
}
I can't see what is causing it. Looking at the error, which says use await
...as you can see I have await
behind it.
Anyone can help please?
Thank you.
Edit: My scenario is using Unit of Work and I have got several layers between controller and the depth of my data layer.