microsoft/aspire · error · InvalidOperationException
Conflicting values for 'CommandTimeout' were found in
Error message
Conflicting values for 'CommandTimeout' were found in {nameof(NpgsqlEntityFrameworkCorePostgreSQLSettings)} and set in DbContextOptions<{typeof(TContext).Name}>. What it means
Thrown when both NpgsqlEntityFrameworkCorePostgreSQLSettings.CommandTimeout and the DbContextOptions' NpgsqlOptionsExtension.CommandTimeout are set to different values — the library refuses to silently pick one of two conflicting sources.
Solutions
- Set CommandTimeout in only one place — remove it from the DbContext options or from the Aspire settings
- Align the two values so they match exactly
- Pass null CommandTimeout in settings to let the DbContext option win
Example fix
// before builder.EnrichNpgsqlDbContext<MyDbContext>(settings => settings.CommandTimeout = 60); // while UseNpgsql(o => o.CommandTimeout(30)) // after builder.EnrichNpgsqlDbContext<MyDbContext>(settings => settings.CommandTimeout = 30); // match the DbContext value // or remove the CommandTimeout call from UseNpgsql
Defensive patterns
Strategy: validation
Validate before calling
var settingsTimeout = aspireSettings.CommandTimeout;
var optionsTimeout = dbContextOptions.Extensions.OfType<NpgsqlOptionsExtension>().FirstOrDefault()?.CommandTimeout;
if (settingsTimeout.HasValue && optionsTimeout.HasValue && settingsTimeout != optionsTimeout)
throw new InvalidOperationException("CommandTimeout differs between Aspire settings and DbContext options."); Try / catch
try
{
builder.EnrichNpgsqlDbContext<MyDbContext>();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Conflicting values for 'CommandTimeout'"))
{
logger.LogError(ex, "CommandTimeout is set in two places with different values.");
throw;
} Prevention
- Pick a single source of truth for CommandTimeout (Aspire settings recommended)
- Audit UseNpgsql/OnConfiguring for CommandTimeout before enriching
- Keep timeout values in one configuration key per environment
When it happens
Trigger: Calling EnrichNpgsqlDbContext with settings.CommandTimeout set while the DbContext's own options (e.g. UseNpgsql(o => o.CommandTimeout(30))) specify a different CommandTimeout value.
Common situations: DbContext configured CommandTimeout in OnConfiguring or options delegate and later Aspire settings also set CommandTimeout; differing values after a config change or copy-paste between environments.
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
- Conflicting values for 'CommandTimeout' were found in
- Conflicting values for 'CommandTimeout' were found in
- Conflicting values for 'CommandTimeout' were found in
- . needs to be set when a custom Execution Strategy is…
- 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/841de1e0786dd432.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs:180
}
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(NpgsqlEntityFrameworkCorePostgreSQLSettings)} 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, NpgsqlEntityFrameworkCorePostgreSQLSettings settings) where TContext : DbContext
{
if (!settings.DisableHealthChecks)
{
// calling MapHealthChecks is the responsibility of the app, not Component
builder.TryAddHealthCheck(
name: typeof(TContext).Name,View on GitHub (pinned to 25830f84bd)