{"record":{"id":"082ee832a9745bc2","repo":"microsoft/aspire","slug":"azuresandboxoptions-autosuspendenabled-must-be-set-when","errorCode":null,"errorMessage":"AzureSandboxOptions.AutoSuspendEnabled must be set when configuring auto-suspend interval or mode.","messagePattern":"AzureSandboxOptions\\.AutoSuspendEnabled must be set when configuring auto-suspend interval or mode\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs","lineNumber":380,"sourceCode":"    private static void ValidateSandboxOptions(AzureSandboxOptions options)\n    {\n        if (!Enum.IsDefined(options.Tier))\n        {\n            throw new ArgumentException($\"'{options.Tier}' is not a valid Azure sandbox tier.\", nameof(options));\n        }\n\n        ValidateOptionalWholeSecondDuration(\n            options.AutoSuspendInterval,\n            nameof(AzureSandboxOptions.AutoSuspendInterval),\n            TimeSpan.FromSeconds(int.MaxValue));\n        ValidateOptionalEnum(options.AutoSuspendMode, nameof(AzureSandboxOptions.AutoSuspendMode));\n        ValidateOptionalWholeSecondDuration(options.AutoDeleteInterval, nameof(AzureSandboxOptions.AutoDeleteInterval));\n        ValidateOptionalEnum(options.AutoDeleteTrigger, nameof(AzureSandboxOptions.AutoDeleteTrigger));\n\n        if (options.AutoSuspendEnabled is null &&\n            (options.AutoSuspendInterval is not null || options.AutoSuspendMode is not null))\n        {\n            throw new ArgumentException(\n                $\"{nameof(AzureSandboxOptions.AutoSuspendEnabled)} must be set when configuring auto-suspend interval or mode.\",\n                nameof(options));\n        }\n\n        if (options.AutoDeleteEnabled is null &&\n            (options.AutoDeleteInterval is not null || options.AutoDeleteTrigger is not null))\n        {\n            throw new ArgumentException(\n                $\"{nameof(AzureSandboxOptions.AutoDeleteEnabled)} must be set when configuring auto-delete interval or trigger.\",\n                nameof(options));\n        }\n\n        if (options.Endpoints is null)\n        {\n            return;\n        }\n\n        var names = new HashSet<string>(StringComparer.OrdinalIgnoreCase);","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs#L362-L398","documentation":"Auto-suspend was partially configured: an auto-suspend interval and/or mode was supplied, but the AutoSuspendEnabled master switch was left unset (null). The library requires the enabling flag to be explicit whenever any auto-suspend detail is provided, to avoid silently guessing whether auto-suspend is on, and throws ArgumentException.","triggerScenarios":"Calling PublishAsAzureSandbox with AzureSandboxOptions where AutoSuspendEnabled is null while AutoSuspendInterval or AutoSuspendMode is non-null.","commonSituations":"Setting only AutoSuspendInterval (assuming the feature turns on implicitly); copying an options object where AutoSuspendEnabled was omitted by the caller; refactoring options and dropping the Enabled assignment.","solutions":["Set AutoSuspendEnabled = true when you want auto-suspend, together with the interval/mode.","If auto-suspend is not wanted, remove the AutoSuspendInterval/AutoSuspendMode values instead of leaving them set.","Validate options before publishing: AutoSuspendEnabled must be non-null whenever either auto-suspend detail is provided."],"exampleFix":"// before\nnew AzureSandboxOptions { AutoSuspendInterval = TimeSpan.FromMinutes(30) };\n\n// after\nnew AzureSandboxOptions\n{\n    AutoSuspendEnabled = true,\n    AutoSuspendInterval = TimeSpan.FromMinutes(30)\n};","handlingStrategy":"validation","validationCode":"if (options.AutoSuspendEnabled is null && (options.AutoSuspendInterval is not null || options.AutoSuspendMode is not null))\n{\n    throw new ArgumentException(\"AutoSuspendEnabled must be set when configuring auto-suspend interval or mode.\");\n}","typeGuard":null,"tryCatchPattern":"try { builder.PublishAsAzureSandbox(options); } catch (ArgumentException ex) when (ex.Message.Contains(\"AutoSuspendEnabled must be set\")) { /* set AutoSuspendEnabled or drop the interval/mode */ }","preventionTips":["Always pair Enabled flags with any detail values when constructing sandbox options.","Build options through a helper that sets Enabled = true whenever interval/mode are supplied.","Load options from configuration and validate all pairs before publishing."],"tags":["azure","sandbox-group","validation","autosuspend","configuration"],"backgroundTag":"missing-required-config-field","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}