A second operation was started on this context 🟪 .NET

EF Core: A second operation was started on this context instance before a previous operation completed

The same DbContext was used concurrently — async calls not awaited, parallel tasks sharing a context, or a context registered as singleton.

Seen on: .NET

Meaning

DbContext isn’t thread-safe. Missing await, Task.WhenAll over queries on one context, or injecting a scoped context into a singleton/background service cause it.

Common causes

  • Missing await on an async EF call
  • Parallel queries (Task.WhenAll) on one context
  • DbContext captured by a singleton/hosted service
  • Blazor Server components sharing a context

⚡ Quick fix

  1. Await every EF call
  2. Use separate contexts (IDbContextFactory) for parallel work
  3. Create scopes in background services

Detailed fix by platform

C#

  1. csharp
    public class Worker(IDbContextFactory<AppDb> factory)
    {
        public async Task RunAsync() { await using var db = await factory.CreateDbContextAsync(); /* ... */ }
    }

How to diagnose

  1. Await — All async calls awaited?
  2. Lifetime — Context lifetime vs consumer
  3. Parallel — WhenAll on one context?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.