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
EnsureCreated() (synchronous) throws when only an asynchronous seed delegate (AsyncSeeder via UseAsyncSeeding) was configured and no synchronous Seeder (UseSeeding) exists (InMemoryDatabaseCreator.cs:80-83). EF refuses to silently skip seeding on a sync code path when the user clearly intended async seeding.
Source
Thrown at src/EFCore.InMemory/Storage/Internal/InMemoryDatabaseCreator.cs:82
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool EnsureCreated()
{
var created = Database.EnsureDatabaseCreated();
var coreOptionsExtension =
_contextOptions.FindExtension<CoreOptionsExtension>()
?? new CoreOptionsExtension();
var seed = coreOptionsExtension.Seeder;
if (seed != null)
{
seed(_currentContext.Context, created);
}
else if (coreOptionsExtension.AsyncSeeder != null)
{
throw new InvalidOperationException(CoreStrings.MissingSeeder);
}
return created;
}
/// <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
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual async Task<bool> EnsureCreatedAsync(CancellationToken cancellationToken = default)
{
var created = Database.EnsureDatabaseCreated();
var coreOptionsExtension =
_contextOptions.FindExtension<CoreOptionsExtension>()
?? new CoreOptionsExtension();View on GitHub (pinned to dbf9771522)
Solutions
- Add UseSeeding(...) with a delegate equivalent to the UseAsyncSeeding delegate so both paths are covered.
- Switch the caller to EnsureCreatedAsync() instead of EnsureCreated().
Example fix
// before
options.UseAsyncSeeding((ctx, _, ct) => SeedAsync(ctx, ct));
// after
options
.UseSeeding((ctx, _) => Seed(ctx))
.UseAsyncSeeding((ctx, _, ct) => SeedAsync(ctx, ct)); Defensive patterns
Strategy: validation
Validate before calling
// Ensure both seeders are configured together before calling sync creation:
optionsBuilder
.UseSeeding((ctx, _) => Seed(ctx))
.UseAsyncSeeding((ctx, _, ct) => SeedAsync(ctx, ct)); Prevention
- Always configure UseSeeding and UseAsyncSeeding together so both sync and async paths work.
- If you only configure one, only call the matching EnsureCreated/EnsureCreatedAsync.
- Keep the two seed delegates logically equivalent to avoid divergence.
When it happens
Trigger: Configuring options with UseAsyncSeeding(...) but not UseSeeding(...), then calling context.Database.EnsureCreated() (the sync method).
Common situations: Setting up database seeding only for the async path and then calling EnsureCreated synchronously in a startup path or test setup.
Related errors
- Invalid number of index sort order values: {numValues} value
- IsDescending and AllDescending cannot both be specified on t
- The number argument cannot be a negative number.
- The value '{value}' provided for argument '{argumentName}' m
- Cosmos-specific methods can only be used when the context is
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/331ad75c3c6c6718.
Report an issue: GitHub.