InvalidOperationException, A second operation started on this context before a previous operation completed.

Problem: InvalidOperationException: A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext, however instance members are not guaranteed to be thread safe. This could also be caused by a nested query being evaluated on the client, if this is the case rewrite the query avoiding nested invocations. Solution: When calling your method prefix it with an "await" in front, e.g. wait yourObject.MethodName(); Chances are that you defined your function as an async hence when calling the function you are not using "await". The error tells you exactly the way it is, when you instantiated a class you also started the DB Context and then tried to use it on the same thread, that is a no no, use await so that the call can be run on a different thread. Hope this helps.

Yes Was this page helpful? No
Yes Was this page helpful? No