microsoft/aspire · error · InvalidOperationException

Conflicting values for 'RequestTimeout' were found in

Error message

Conflicting values for 'RequestTimeout' were found in {nameof(EntityFrameworkCoreCosmosSettings)} and set in DbContextOptions<{typeof(TContext).Name}>.

What it means

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.

Solutions

  1. Remove the direct optionsBuilder.RequestTimeout(...) call and configure RequestTimeout only in EntityFrameworkCoreCosmosSettings.
  2. Or remove RequestTimeout from settings and keep the value on DbContextOptions (set settings.RequestTimeout to null).
  3. Align both values so they match if both must exist temporarily.

Example fix

// before
builder.AddCosmosDbContext<OrderContext>("cosmosdb", "shop", s => s.RequestTimeout = TimeSpan.FromMinutes(2), o => o.RequestTimeout(TimeSpan.FromSeconds(30)));
// after
builder.AddCosmosDbContext<OrderContext>("cosmosdb", "shop", s => s.RequestTimeout = TimeSpan.FromSeconds(30));
Defensive patterns

Strategy: validation

Validate before calling

// ensure only one source sets RequestTimeout
bool conflicts = !string.IsNullOrEmpty(builder.Configuration["Aspire:Microsoft:EntityFrameworkCore:Cosmos:RequestTimeout"])
                 && setsRequestTimeoutInOptions;
if (conflicts) { throw new InvalidOperationException("Remove the duplicate RequestTimeout setting."); }

Type guard

bool SingleTimeoutSource(TimeSpan? settingsTimeout, CosmosOptionsExtension? ext) => settingsTimeout is null || ext?.RequestTimeout is null || settingsTimeout == ext.RequestTimeout;

Try / catch

try { builder.AddCosmosDbContext<OrderContext>("cosmosdb", "shop"); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Conflicting values for 'RequestTimeout'")) { // remove the direct optionsBuilder.RequestTimeout call and retry }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/4933368350cc3b3d. Report an issue: GitHub.

Appendix: source

Thrown at src/Components/Aspire.Microsoft.EntityFrameworkCore.Cosmos/AspireAzureEFCoreCosmosExtensions.cs:226

        }
        else
        {
            builder.PatchServiceDescriptor<TContext>();
        }

        ConfigureInstrumentation<TContext>(builder, settings);
    }

    private static void ConfigureRequestTimeout<TContext>(DbContextOptionsBuilder builder, EntityFrameworkCoreCosmosSettings settings)
    {
#pragma warning disable EF1001 // Internal EF Core API usage.
        var extension = builder.Options.FindExtension<CosmosOptionsExtension>();

        if (extension != null &&
            extension.RequestTimeout.HasValue &&
            extension.RequestTimeout != settings.RequestTimeout)
        {
            throw new InvalidOperationException($"Conflicting values for 'RequestTimeout' were found in {nameof(EntityFrameworkCoreCosmosSettings)} and set in DbContextOptions<{typeof(TContext).Name}>.");
        }

        extension?.WithRequestTimeout(settings.RequestTimeout);
#pragma warning restore EF1001 // Internal EF Core API usage.
    }

    private static void ConfigureInstrumentation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties)] TContext>(IHostApplicationBuilder builder, EntityFrameworkCoreCosmosSettings settings) where TContext : DbContext
    {
        if (!settings.DisableTracing)
        {
            builder.Services.AddOpenTelemetry().WithTracing(tracerProviderBuilder =>
            {
                tracerProviderBuilder.AddSource("Azure.Cosmos.Operation");
            });
        }
    }
}

View on GitHub (pinned to 25830f84bd)