microsoft/aspire · error · InvalidOperationException

. needs to be set when a custom Execution Strategy is…

Error message

{nameof(PomeloEntityFrameworkCoreMySqlSettings)}.{nameof(PomeloEntityFrameworkCoreMySqlSettings.DisableRetry)} needs to be set when a custom Execution Strategy is configured.

What it means

Aspire's MySQL EF enrichment replaces the default retry execution strategy with its own MySqlExecutionStrategy when EnableRetry is on. If the DbContext was configured with a custom execution strategy (any subclass of ExecutionStrategy other than MySqlExecutionStrategy), Aspire refuses to silently discard it. Setting DisableRetry tells Aspire you accept keeping the custom strategy instead.

Solutions

  1. Set DisableRetry = true in PomeloEntityFrameworkCoreMySqlSettings so Aspire leaves your custom execution strategy in place.
  2. Remove the custom execution strategy registration if you want Aspire's built-in MySqlExecutionStrategy retry (EnableRetryOnFailure) instead.
  3. Align strategies: wrap your custom logic in a class derived so that it is intentionally chosen, and keep DisableRetry = true, documenting why.

Example fix

// before
builder.EnrichMySqlDbContext<MyDbContext>(settings => settings.DisableRetry = false);
optionsBuilder.ExecutionStrategy(ctx => new CustomExecutionStrategy(ctx, 5));

// after
builder.EnrichMySqlDbContext<MyDbContext>(settings => settings.DisableRetry = true); // keep custom strategy
// OR remove CustomExecutionStrategy and let Aspire enable MySqlExecutionStrategy retry
Defensive patterns

Strategy: validation

Validate before calling

if (!settings.DisableRetry && options.ExecutionStrategy != null)
    throw new InvalidOperationException("Set DisableRetry = true before enriching a DbContext with a custom execution strategy.");

Try / catch

try { builder.EnrichMySqlDbContext<TContext>(name, settings); }
catch (InvalidOperationException ex) when (ex.Message.Contains("DisableRetry"))
{ /* log guidance: either disable retry or remove custom strategy */ }

Prevention

When it happens

Trigger: Calling AddEnrichMySqlDbContext (or EnrichMySqlDbContext) with PomeloEntityFrameworkCoreMySqlSettings.DisableRetry = false (default) while the DbContextOptions already have a custom ExecutionStrategy registered (e.g. via options.ExecutionStrategy(...) or a MySqlExecutionStrategy subclass).

Common situations: Apps that previously registered a custom retry strategy (custom backoff, fault-injection strategy for tests, k8s-aware retry) then adopt Aspire's enrichment; migration from manual Pomelo setup to Aspire hosting while keeping old strategy code.

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/95ba156757be5282. Report an issue: GitHub.

Appendix: source

Thrown at src/Components/Aspire.Pomelo.EntityFrameworkCore.MySql/AspireEFMySqlExtensions.cs:209

                        var extension = optionsBuilder.Options.FindExtension<MySqlOptionsExtension>();

                        if (!settings.DisableRetry)
                        {
                            var executionStrategy = extension?.ExecutionStrategyFactory?.Invoke(new ExecutionStrategyDependencies(null!, optionsBuilder.Options, null!));

                            if (executionStrategy != null)
                            {
                                if (executionStrategy is MySqlRetryingExecutionStrategy)
                                {
                                    // Keep custom Retry strategy.
                                    // Any sub-class of MySqlRetryingExecutionStrategy is a valid retry strategy
                                    // which shouldn't be replaced even with DisableRetry == false
                                }
                                else if (executionStrategy.GetType() != typeof(MySqlExecutionStrategy))
                                {
                                    // Check MySqlExecutionStrategy specifically (no 'is'), any sub-class is treated as a custom strategy.

                                    throw new InvalidOperationException($"{nameof(PomeloEntityFrameworkCoreMySqlSettings)}.{nameof(PomeloEntityFrameworkCoreMySqlSettings.DisableRetry)} needs to be set when a custom Execution Strategy is configured.");
                                }
                                else
                                {
                                    options.EnableRetryOnFailure();
                                }
                            }
                            else
                            {
                                options.EnableRetryOnFailure();
                            }
                        }

                        if (settings.CommandTimeout.HasValue)
                        {
                            if (extension != null &&
                                extension.CommandTimeout.HasValue &&
                                extension.CommandTimeout != settings.CommandTimeout)
                            {

View on GitHub (pinned to 25830f84bd)