{"record":{"id":"841de1e0786dd432","repo":"microsoft/aspire","slug":"conflicting-values-for-commandtimeout-were-found-in-nameof-841de1","errorCode":null,"errorMessage":"Conflicting values for 'CommandTimeout' were found in {nameof(NpgsqlEntityFrameworkCorePostgreSQLSettings)} 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.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs","lineNumber":180,"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(NpgsqlEntityFrameworkCorePostgreSQLSettings)} and set in DbContextOptions<{typeof(TContext).Name}>.\");\n                            }\n\n                            options.CommandTimeout(settings.CommandTimeout);\n                        }\n                    });\n                }\n#pragma warning restore EF1001 // Internal EF Core API usage.\n            }\n        }\n    }\n\n    private static void ConfigureInstrumentation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties)] TContext>(IHostApplicationBuilder builder, NpgsqlEntityFrameworkCorePostgreSQLSettings settings) where TContext : DbContext\n    {\n        if (!settings.DisableHealthChecks)\n        {\n            // calling MapHealthChecks is the responsibility of the app, not Component\n            builder.TryAddHealthCheck(\n                name: typeof(TContext).Name,","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs#L162-L198","documentation":"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.","triggerScenarios":"Calling EnrichNpgsqlDbContext with settings.CommandTimeout set while the DbContext's own options (e.g. UseNpgsql(o => o.CommandTimeout(30))) specify a different CommandTimeout value.","commonSituations":"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.","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"],"exampleFix":"// before\nbuilder.EnrichNpgsqlDbContext<MyDbContext>(settings => settings.CommandTimeout = 60);\n// while UseNpgsql(o => o.CommandTimeout(30))\n// after\nbuilder.EnrichNpgsqlDbContext<MyDbContext>(settings => settings.CommandTimeout = 30); // match the DbContext value\n// or remove the CommandTimeout call from UseNpgsql","handlingStrategy":"validation","validationCode":"var settingsTimeout = aspireSettings.CommandTimeout;\nvar optionsTimeout = dbContextOptions.Extensions.OfType<NpgsqlOptionsExtension>().FirstOrDefault()?.CommandTimeout;\nif (settingsTimeout.HasValue && optionsTimeout.HasValue && settingsTimeout != optionsTimeout)\n    throw new InvalidOperationException(\"CommandTimeout differs between Aspire settings and DbContext options.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    builder.EnrichNpgsqlDbContext<MyDbContext>();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Conflicting values for 'CommandTimeout'\"))\n{\n    logger.LogError(ex, \"CommandTimeout is set in two places with different values.\");\n    throw;\n}","preventionTips":["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"],"tags":["postgresql","ef-core","command-timeout","configuration-conflict"],"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"}