{"record":{"id":"79b3fb09769c6f53","repo":"microsoft/aspire","slug":"nameof-npgsqlentityframeworkcorepostgresqlsettings-nameof","errorCode":null,"errorMessage":"{nameof(NpgsqlEntityFrameworkCorePostgreSQLSettings)}.{nameof(NpgsqlEntityFrameworkCorePostgreSQLSettings.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.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs","lineNumber":161,"sourceCode":"                        var extension = optionsBuilder.Options.FindExtension<NpgsqlOptionsExtension>();\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 NpgsqlRetryingExecutionStrategy)\n                                {\n                                    // Keep custom Retry strategy.\n                                    // Any sub-class of NpgsqlRetryingExecutionStrategy is a valid retry strategy\n                                    // which shouldn't be replaced even with DisableRetry == false\n                                }\n                                else if (executionStrategy.GetType() != typeof(NpgsqlExecutionStrategy))\n                                {\n                                    // Check NpgsqlExecutionStrategy specifically (no 'is'), any sub-class is treated as a custom strategy.\n\n                                    throw new InvalidOperationException($\"{nameof(NpgsqlEntityFrameworkCorePostgreSQLSettings)}.{nameof(NpgsqlEntityFrameworkCorePostgreSQLSettings.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":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs#L143-L179","documentation":"EnrichNpgsqlDbContext detects a custom ExecutionStrategy registered on the DbContextOptions and throws because automatic retry cannot be combined with a custom strategy — the developer must explicitly set DisableRetry to acknowledge retrying is disabled.","triggerScenarios":"Calling EnrichNpgsqlDbContext on a DbContext whose options already have an execution strategy whose exact type is not NpgsqlExecutionStrategy (e.g. from UseNpgsql with EnableRetryOnFailure customization or a custom ExecutionStrategy impl), while NpgsqlEntityFrameworkCorePostgreSQLSettings.DisableRetry is false/not set.","commonSituations":"Migrating an existing DbContext that configured its own retrying strategy into Aspire's enrichment pipeline; subclassing NpgsqlExecutionStrategy for custom logic; mixing UseNpgsql(...) options with Aspire enrichment.","solutions":["Set DisableRetry = true in NpgsqlEntityFrameworkCorePostgreSQLSettings (builder.EnrichNpgsqlDbContext<TContext>(settings => settings.DisableRetry = true))","Remove the custom execution strategy so EF Core uses the default NpgsqlExecutionStrategy and let Aspire manage retries","Register the custom strategy only when explicitly disabling Aspire retry"],"exampleFix":"// before\nbuilder.EnrichNpgsqlDbContext<MyDbContext>(); // DbContext uses custom execution strategy\n// after\nbuilder.EnrichNpgsqlDbContext<MyDbContext>(settings => settings.DisableRetry = true);","handlingStrategy":"validation","validationCode":"bool hasCustomStrategy = myDbContextOptions.ExecutionStrategy is not null &&\n    myDbContextOptions.ExecutionStrategy.GetType() != typeof(NpgsqlExecutionStrategy);\nif (hasCustomStrategy)\n    aspireSettings.DisableRetry = true; // set before EnrichNpgsqlDbContext","typeGuard":null,"tryCatchPattern":"try\n{\n    builder.EnrichNpgsqlDbContext<MyDbContext>();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"DisableRetry\"))\n{\n    logger.LogError(ex, \"Custom execution strategy conflicts with Aspire retry settings.\");\n    throw;\n}","preventionTips":["Decide up front whether Aspire or the DbContext owns retry policy","Set DisableRetry whenever the DbContext configures its own execution strategy","Avoid subclassing NpgsqlExecutionStrategy when using Aspire enrichment"],"tags":["postgresql","ef-core","execution-strategy","retry","configuration"],"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"}