{"record":{"id":"05060d72424c4d06","repo":"microsoft/aspire","slug":"conflicting-values-for-commandtimeout-were-found-in-nameof","errorCode":null,"errorMessage":"Conflicting values for 'CommandTimeout' were found in {nameof(MicrosoftEntityFrameworkCoreSqlServerSettings)} and set in DbContextOptions<{typeof(TContext).Name}>.","messagePattern":"Conflicting values for 'CommandTimeout' were found in (.+?) and set in DbContextOptions<(.+?)>\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Aspire.Microsoft.EntityFrameworkCore.SqlServer/AspireSqlServerEFCoreSqlClientExtensions.cs","lineNumber":165,"sourceCode":"                            }\n                            else\n                            {\n                                options.EnableRetryOnFailure();\n                            }\n                        }\n                        else\n                        {\n                            options.EnableRetryOnFailure();\n                        }\n                    }\n\n                    if (settings.CommandTimeout.HasValue)\n                    {\n                        if (extension != null &&\n                            extension.CommandTimeout.HasValue &&\n                            extension.CommandTimeout != settings.CommandTimeout)\n                        {\n                            throw new InvalidOperationException($\"Conflicting values for 'CommandTimeout' were found in {nameof(MicrosoftEntityFrameworkCoreSqlServerSettings)} and set in DbContextOptions<{typeof(TContext).Name}>.\");\n                        }\n\n                        options.CommandTimeout(settings.CommandTimeout);\n                    }\n                }));\n            }\n        }\n#pragma warning restore EF1001 // Internal EF Core API usage.\n    }\n\n    private static void ConfigureInstrumentation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties)] TContext>(IHostApplicationBuilder builder, MicrosoftEntityFrameworkCoreSqlServerSettings settings) where TContext : DbContext\n    {\n        if (!settings.DisableTracing)\n        {\n            builder.Services.AddOpenTelemetry().WithTracing(tracerProviderBuilder =>\n            {\n                tracerProviderBuilder.AddSqlClientInstrumentation();\n            });","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Aspire.Microsoft.EntityFrameworkCore.SqlServer/AspireSqlServerEFCoreSqlClientExtensions.cs#L147-L183","documentation":"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.","triggerScenarios":"Setting options.CommandTimeout(...) in the configureDbContextOptions callback (or OnConfiguring) with a value different from CommandTimeout in MicrosoftEntityFrameworkCoreSqlServerSettings (appsettings or settings callback).","commonSituations":"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.","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."],"exampleFix":"// before\nbuilder.AddSqlServerDbContext<OrderContext>(\"sqldb\", s => s.CommandTimeout = 30, o => o.CommandTimeout(120));\n// after\nbuilder.AddSqlServerDbContext<OrderContext>(\"sqldb\", s => s.CommandTimeout = 30);","handlingStrategy":"validation","validationCode":"// detect duplicate CommandTimeout sources before registration\nvar cfgTimeout = builder.Configuration[\"Aspire:Microsoft:EntityFrameworkCore:SqlServer:CommandTimeout\"];\nif (cfgTimeout is not null && setsCommandTimeoutInOptions && cfgTimeout != optionsTimeout?.ToString())\n{\n    throw new InvalidOperationException(\"CommandTimeout set in both settings and DbContextOptions.\");\n}","typeGuard":"bool SingleCommandTimeoutSource(int? settingsTimeout, int? optionsTimeout) => settingsTimeout is null || optionsTimeout is null || settingsTimeout == optionsTimeout;","tryCatchPattern":"try { builder.AddSqlServerDbContext<OrderContext>(\"sqldb\", settingsCallback); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Conflicting values for 'CommandTimeout'\")) { // delete the options.CommandTimeout(...) call and keep the settings value }","preventionTips":["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."],"tags":["ef-core","sql-server","conflicting-settings","command-timeout"],"backgroundTag":"conflicting-config-options","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}