{"record":{"id":"8f9278107bb6d12b","repo":"microsoft/aspire","slug":"nameof-microsoftentityframeworkcoresqlserversettings-nameof","errorCode":null,"errorMessage":"{nameof(MicrosoftEntityFrameworkCoreSqlServerSettings)}.{nameof(MicrosoftEntityFrameworkCoreSqlServerSettings.DisableRetry)} needs to be set when a custom Execution Strategy is configured.","messagePattern":"(.+?)\\.(.+?) needs to be set when a custom Execution Strategy is configured\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Aspire.Microsoft.EntityFrameworkCore.SqlServer/AspireSqlServerEFCoreSqlClientExtensions.cs","lineNumber":146,"sourceCode":"                    var extension = optionsBuilder.Options.FindExtension<SqlServerOptionsExtension>();\n\n                    if (!settings.DisableRetry)\n                    {\n                        var executionStrategy = extension?.ExecutionStrategyFactory?.Invoke(new ExecutionStrategyDependencies(null!, optionsBuilder.Options, null!));\n\n                        if (executionStrategy != null)\n                        {\n                            if (executionStrategy is SqlServerRetryingExecutionStrategy)\n                            {\n                                // Keep custom Retry strategy.\n                                // Any sub-class of SqlServerRetryingExecutionStrategy is a valid retry strategy\n                                // which shouldn't be replaced even with DisableRetry == false\n                            }\n                            else if (executionStrategy.GetType() != typeof(SqlServerExecutionStrategy))\n                            {\n                                // Check SqlServerExecutionStrategy specifically (no 'is'), any sub-class is treated as a custom strategy.\n\n                                throw new InvalidOperationException($\"{nameof(MicrosoftEntityFrameworkCoreSqlServerSettings)}.{nameof(MicrosoftEntityFrameworkCoreSqlServerSettings.DisableRetry)} needs to be set when a custom Execution Strategy is configured.\");\n                            }\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                        {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Aspire.Microsoft.EntityFrameworkCore.SqlServer/AspireSqlServerEFCoreSqlClientExtensions.cs#L128-L164","documentation":"Aspire detects a custom (non-default) SQL Server ExecutionStrategy configured on the DbContext options. Because Aspire manages retry behavior via DisableRetry/EnableRetryOnFailure, a custom strategy would be clobbered or conflict; the developer must opt out by setting DisableRetry = true so Aspire leaves the custom strategy alone.","triggerScenarios":"Registering a custom ExecutionStrategy (any class derived from SqlServerExecutionStrategy or replacing it via ExecutionStrategy extension) in configureDbContextOptions while MicrosoftEntityFrameworkCoreSqlServerSettings.DisableRetry is not set to true.","commonSituations":"Apps that implemented custom transient-fault handling before adopting Aspire; retry policy wrappers added via EF Core interceptors/strategies; copy-pasting pre-Aspire OnConfiguring code into the Aspire configureDbContextOptions callback.","solutions":["Set DisableRetry = true in MicrosoftEntityFrameworkCoreSqlServerSettings (config section or settings callback) to keep the custom strategy.","Or remove the custom ExecutionStrategy registration and let Aspire enable the built-in SqlServerExecutionStrategy retry-on-failure.","If the custom strategy subclasses SqlServerExecutionStrategy intentionally, subclass or align so the exact type matches, or disable Aspire retry."],"exampleFix":"// before\nbuilder.AddSqlServerDbContext<OrderContext>(\"sqldb\", null, o => o.ExecutionStrategy(ctx => new MyCustomStrategy(ctx)));\n// after\nbuilder.AddSqlServerDbContext<OrderContext>(\"sqldb\", s => s.DisableRetry = true, o => o.ExecutionStrategy(ctx => new MyCustomStrategy(ctx)));","handlingStrategy":"validation","validationCode":"// if you register a custom ExecutionStrategy, also assert DisableRetry\nif (registersCustomExecutionStrategy &&\n    builder.Configuration[\"Aspire:Microsoft:EntityFrameworkCore:SqlServer:DisableRetry\"] != \"true\")\n{\n    throw new InvalidOperationException(\"Set DisableRetry=true when using a custom ExecutionStrategy.\");\n}","typeGuard":"bool CustomStrategyAllowed(bool hasCustomStrategy, bool disableRetry) => !hasCustomStrategy || disableRetry;","tryCatchPattern":"try { builder.AddSqlServerDbContext<OrderContext>(\"sqldb\", settingsCallback, optionsCallback); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"DisableRetry\")) { // set DisableRetry=true in settingsCallback or drop the custom strategy }","preventionTips":["Pair every custom ExecutionStrategy registration with DisableRetry=true.","Prefer Aspire's built-in retry (EnableRetryOnFailure) over custom strategies when migrating.","Document custom retry behavior near the DbContext registration."],"tags":["ef-core","sql-server","execution-strategy","conflicting-settings"],"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"}