dotnet/efcore · error · InvalidOperationException

A synchronous store management operation was performed and n

Error message

A synchronous store management operation was performed and no synchronous seed delegate has been provided, however an asynchronous seed delegate was. Set 'UseSeeding' option with a delegate equivalent to the one supplied in 'UseAsyncSeeding'.

What it means

Thrown in the synchronous Migrator.Migrate path when `UseAsyncSeeding` was configured but no matching synchronous seed delegate (`UseSeeding`) was supplied. The sync migrate performed a synchronous store operation and then tried to seed synchronously, but only an async seeder exists.

Source

Thrown at src/EFCore.Relational/Migrations/Internal/Migrator.cs:203

                    getCommands(), _connection, state, commitTransaction: useTransaction, MigrationTransactionIsolationLevel);
            }

            var coreOptionsExtension =
                _contextOptions.FindExtension<CoreOptionsExtension>()
                ?? new CoreOptionsExtension();

            var seed = coreOptionsExtension.Seeder;
            if (seed != null)
            {
                if (!state.SeedingCompleted)
                {
                    seed(context, state.AnyOperationPerformed);
                    state.SeedingCompleted = true;
                }
            }
            else if (coreOptionsExtension.AsyncSeeder != null)
            {
                throw new InvalidOperationException(CoreStrings.MissingSeeder);
            }

            state.Transaction?.Commit();
            return state.AnyOperationPerformed;
        }
        finally
        {
            state.DatabaseLock?.Dispose();
            state.DatabaseLock = null;
            state.Transaction?.Dispose();
            state.Transaction = null;
            _connection.Close();
        }
    }

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in

View on GitHub (pinned to dbf9771522)

Solutions

  1. Provide a synchronous seeder too: call `UseSeeding` with a delegate equivalent to your `UseAsyncSeeding`.
  2. Switch the caller to `MigrateAsync()` so the async seeder is used.
  3. If seeding is not needed for the sync path, remove the `UseAsyncSeeding` registration.

Example fix

// before
options.UseSqlServer(cs)
  .UseAsyncSeeding((ctx, _, ct) => SeedAsync(ctx, ct));
await db.Database.MigrateAsync(); // ok
// someone calls db.Database.Migrate(); // throws
// after
options.UseSqlServer(cs)
  .UseSeeding((ctx, _) => Seed(ctx))
  .UseAsyncSeeding((ctx, _, ct) => SeedAsync(ctx, ct));
Defensive patterns

Strategy: validation

Validate before calling

// If you register an async seeder, also register a sync one before sync Migrate.
var core = options.FindExtension<CoreOptionsExtension>();
if (core?.AsyncSeeder is not null && core?.Seeder is null)
    throw new InvalidOperationException("Register UseSeeding alongside UseAsyncSeeding to support synchronous Migrate.");

Prevention

When it happens

Trigger: Calling `Database.Migrate()` (synchronous) after configuring only `.UseAsyncSeeding(...)` via `UseSeeding`/`UseAsyncSeeding` options, without a matching `.UseSeeding(...)` delegate.

Common situations: Configuring async-only seeding in startup and then a synchronous code path (hosted service, legacy code) calls `Migrate()`; partial migration from sync to async seeding APIs.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/0cc1dba5d1b3a284. Report an issue: GitHub.