{"record":{"id":"4933368350cc3b3d","repo":"microsoft/aspire","slug":"conflicting-values-for-requesttimeout-were-found-in-nameof","errorCode":null,"errorMessage":"Conflicting values for 'RequestTimeout' were found in {nameof(EntityFrameworkCoreCosmosSettings)} and set in DbContextOptions<{typeof(TContext).Name}>.","messagePattern":"Conflicting values for 'RequestTimeout' were found in (.+?) and set in DbContextOptions<(.+?)>\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Aspire.Microsoft.EntityFrameworkCore.Cosmos/AspireAzureEFCoreCosmosExtensions.cs","lineNumber":226,"sourceCode":"        }\n        else\n        {\n            builder.PatchServiceDescriptor<TContext>();\n        }\n\n        ConfigureInstrumentation<TContext>(builder, settings);\n    }\n\n    private static void ConfigureRequestTimeout<TContext>(DbContextOptionsBuilder builder, EntityFrameworkCoreCosmosSettings settings)\n    {\n#pragma warning disable EF1001 // Internal EF Core API usage.\n        var extension = builder.Options.FindExtension<CosmosOptionsExtension>();\n\n        if (extension != null &&\n            extension.RequestTimeout.HasValue &&\n            extension.RequestTimeout != settings.RequestTimeout)\n        {\n            throw new InvalidOperationException($\"Conflicting values for 'RequestTimeout' were found in {nameof(EntityFrameworkCoreCosmosSettings)} and set in DbContextOptions<{typeof(TContext).Name}>.\");\n        }\n\n        extension?.WithRequestTimeout(settings.RequestTimeout);\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, EntityFrameworkCoreCosmosSettings settings) where TContext : DbContext\n    {\n        if (!settings.DisableTracing)\n        {\n            builder.Services.AddOpenTelemetry().WithTracing(tracerProviderBuilder =>\n            {\n                tracerProviderBuilder.AddSource(\"Azure.Cosmos.Operation\");\n            });\n        }\n    }\n}\n","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Aspire.Microsoft.EntityFrameworkCore.Cosmos/AspireAzureEFCoreCosmosExtensions.cs#L208-L244","documentation":"Aspire enforces a single source of truth for the Cosmos request timeout. If EntityFrameworkCoreCosmosSettings.RequestTimeout differs from a RequestTimeout already set directly on DbContextOptions via CosmosOptionsExtension, the extension throws rather than silently overriding one value. Set it in one place only.","triggerScenarios":"Calling optionsBuilder.RequestTimeout(TimeSpan) inside the configureDbContextOptions callback (or via OnConfiguring) while also setting RequestTimeout in EntityFrameworkCoreCosmosSettings (config section or Configure Settings callback) with a different value.","commonSituations":"Migrating from raw EF Core registration to Aspire while keeping old per-context timeout code; central config sets a default timeout that differs from per-context code; team convention set in one layer conflicts with appsettings.","solutions":["Remove the direct optionsBuilder.RequestTimeout(...) call and configure RequestTimeout only in EntityFrameworkCoreCosmosSettings.","Or remove RequestTimeout from settings and keep the value on DbContextOptions (set settings.RequestTimeout to null).","Align both values so they match if both must exist temporarily."],"exampleFix":"// before\nbuilder.AddCosmosDbContext<OrderContext>(\"cosmosdb\", \"shop\", s => s.RequestTimeout = TimeSpan.FromMinutes(2), o => o.RequestTimeout(TimeSpan.FromSeconds(30)));\n// after\nbuilder.AddCosmosDbContext<OrderContext>(\"cosmosdb\", \"shop\", s => s.RequestTimeout = TimeSpan.FromSeconds(30));","handlingStrategy":"validation","validationCode":"// ensure only one source sets RequestTimeout\nbool conflicts = !string.IsNullOrEmpty(builder.Configuration[\"Aspire:Microsoft:EntityFrameworkCore:Cosmos:RequestTimeout\"])\n                 && setsRequestTimeoutInOptions;\nif (conflicts) { throw new InvalidOperationException(\"Remove the duplicate RequestTimeout setting.\"); }","typeGuard":"bool SingleTimeoutSource(TimeSpan? settingsTimeout, CosmosOptionsExtension? ext) => settingsTimeout is null || ext?.RequestTimeout is null || settingsTimeout == ext.RequestTimeout;","tryCatchPattern":"try { builder.AddCosmosDbContext<OrderContext>(\"cosmosdb\", \"shop\"); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Conflicting values for 'RequestTimeout'\")) { // remove the direct optionsBuilder.RequestTimeout call and retry }","preventionTips":["Treat Aspire component settings as the single source of truth for client options.","Do not call Cosmos EF optionsBuilder extension methods inside configureDbContextOptions.","Search the codebase for RequestTimeout before introducing it in settings."],"tags":["ef-core","azure-cosmos","conflicting-settings","request-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"}