microsoft/aspire · error · InvalidOperationException
Conflicting values for 'CommandTimeout' were found in
Error message
Conflicting values for 'CommandTimeout' were found in {nameof(MicrosoftEntityFrameworkCoreSqlServerSettings)} and set in DbContextOptions<{typeof(TContext).Name}>. What it means
Aspire enforces a single source of truth for the SQL command timeout. If MicrosoftEntityFrameworkCoreSqlServerSettings.CommandTimeout is set and a different CommandTimeout was already applied directly to DbContextOptions, the extension throws instead of silently overriding one of them. Configure the value in exactly one place.
Solutions
- Remove the options.CommandTimeout(...) call and set CommandTimeout only in MicrosoftEntityFrameworkCoreSqlServerSettings.
- Or remove CommandTimeout from settings (leave null) and rely on the value set directly on DbContextOptions.
- Make both values identical if both sources must remain during a migration.
Example fix
// before
builder.AddSqlServerDbContext<OrderContext>("sqldb", s => s.CommandTimeout = 30, o => o.CommandTimeout(120));
// after
builder.AddSqlServerDbContext<OrderContext>("sqldb", s => s.CommandTimeout = 30); Defensive patterns
Strategy: validation
Validate before calling
// detect duplicate CommandTimeout sources before registration
var cfgTimeout = builder.Configuration["Aspire:Microsoft:EntityFrameworkCore:SqlServer:CommandTimeout"];
if (cfgTimeout is not null && setsCommandTimeoutInOptions && cfgTimeout != optionsTimeout?.ToString())
{
throw new InvalidOperationException("CommandTimeout set in both settings and DbContextOptions.");
} Type guard
bool SingleCommandTimeoutSource(int? settingsTimeout, int? optionsTimeout) => settingsTimeout is null || optionsTimeout is null || settingsTimeout == optionsTimeout;
Try / catch
try { builder.AddSqlServerDbContext<OrderContext>("sqldb", settingsCallback); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Conflicting values for 'CommandTimeout'")) { // delete the options.CommandTimeout(...) call and keep the settings value } Prevention
- Set CommandTimeout only in MicrosoftEntityFrameworkCoreSqlServerSettings.
- Audit appsettings for legacy CommandTimeout keys before adopting Aspire registration.
- Keep timeout values in one config layer (settings section) per environment.
When it happens
Trigger: Setting options.CommandTimeout(...) in the configureDbContextOptions callback (or OnConfiguring) with a value different from CommandTimeout in MicrosoftEntityFrameworkCoreSqlServerSettings (appsettings or settings callback).
Common situations: appsettings 'Aspire:Microsoft:EntityFrameworkCore:SqlServer:CommandTimeout' left from an earlier config while context code sets its own; upgrading to Aspire but keeping legacy per-context timeout; environment-specific config overriding a value the code also sets.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- . needs to be set when a custom Execution Strategy is…
- Conflicting values for 'CommandTimeout' were found in
- Conflicting values for 'CommandTimeout' were found in
- Conflicting values for 'RequestTimeout' were found in
- A database name is required but was not provided. Specify…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/05060d72424c4d06.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Aspire.Microsoft.EntityFrameworkCore.SqlServer/AspireSqlServerEFCoreSqlClientExtensions.cs:165
}
else
{
options.EnableRetryOnFailure();
}
}
else
{
options.EnableRetryOnFailure();
}
}
if (settings.CommandTimeout.HasValue)
{
if (extension != null &&
extension.CommandTimeout.HasValue &&
extension.CommandTimeout != settings.CommandTimeout)
{
throw new InvalidOperationException($"Conflicting values for 'CommandTimeout' were found in {nameof(MicrosoftEntityFrameworkCoreSqlServerSettings)} and set in DbContextOptions<{typeof(TContext).Name}>.");
}
options.CommandTimeout(settings.CommandTimeout);
}
}));
}
}
#pragma warning restore EF1001 // Internal EF Core API usage.
}
private static void ConfigureInstrumentation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties)] TContext>(IHostApplicationBuilder builder, MicrosoftEntityFrameworkCoreSqlServerSettings settings) where TContext : DbContext
{
if (!settings.DisableTracing)
{
builder.Services.AddOpenTelemetry().WithTracing(tracerProviderBuilder =>
{
tracerProviderBuilder.AddSqlClientInstrumentation();
});View on GitHub (pinned to 25830f84bd)