microsoft/aspire · error · ArgumentException

AzureSandboxOptions.AutoDeleteEnabled must be set when…

Error message

AzureSandboxOptions.AutoDeleteEnabled must be set when configuring auto-delete interval or trigger.

What it means

Auto-delete was partially configured: an auto-delete interval and/or trigger was supplied, but the AutoDeleteEnabled master switch was left unset (null). The library requires the enabling flag to be explicit whenever any auto-delete detail is provided, and throws ArgumentException otherwise.

Solutions

  1. Set AutoDeleteEnabled = true alongside the interval/trigger to opt into auto-delete.
  2. If auto-delete is unwanted, remove the AutoDeleteInterval/AutoDeleteTrigger values.
  3. Validate options before publishing: AutoDeleteEnabled must be non-null whenever either auto-delete detail is provided.

Example fix

// before
new AzureSandboxOptions { AutoDeleteInterval = TimeSpan.FromDays(7) };

// after
new AzureSandboxOptions
{
    AutoDeleteEnabled = true,
    AutoDeleteInterval = TimeSpan.FromDays(7)
};
Defensive patterns

Strategy: validation

Validate before calling

if (options.AutoDeleteEnabled is null && (options.AutoDeleteInterval is not null || options.AutoDeleteTrigger is not null))
{
    throw new ArgumentException("AutoDeleteEnabled must be set when configuring auto-delete interval or trigger.");
}

Try / catch

try { builder.PublishAsAzureSandbox(options); } catch (ArgumentException ex) when (ex.Message.Contains("AutoDeleteEnabled must be set")) { /* set AutoDeleteEnabled or remove the interval/trigger */ }

Prevention

When it happens

Trigger: Calling PublishAsAzureSandbox with AzureSandboxOptions where AutoDeleteEnabled is null while AutoDeleteInterval or AutoDeleteTrigger is non-null.

Common situations: Setting only AutoDeleteInterval or AutoDeleteTrigger and assuming auto-delete enables itself; options objects constructed from configuration where the Enabled flag key is missing; copy-paste of auto-suspend options renamed to auto-delete without the Enabled flag.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs:388

            options.AutoSuspendInterval,
            nameof(AzureSandboxOptions.AutoSuspendInterval),
            TimeSpan.FromSeconds(int.MaxValue));
        ValidateOptionalEnum(options.AutoSuspendMode, nameof(AzureSandboxOptions.AutoSuspendMode));
        ValidateOptionalWholeSecondDuration(options.AutoDeleteInterval, nameof(AzureSandboxOptions.AutoDeleteInterval));
        ValidateOptionalEnum(options.AutoDeleteTrigger, nameof(AzureSandboxOptions.AutoDeleteTrigger));

        if (options.AutoSuspendEnabled is null &&
            (options.AutoSuspendInterval is not null || options.AutoSuspendMode is not null))
        {
            throw new ArgumentException(
                $"{nameof(AzureSandboxOptions.AutoSuspendEnabled)} must be set when configuring auto-suspend interval or mode.",
                nameof(options));
        }

        if (options.AutoDeleteEnabled is null &&
            (options.AutoDeleteInterval is not null || options.AutoDeleteTrigger is not null))
        {
            throw new ArgumentException(
                $"{nameof(AzureSandboxOptions.AutoDeleteEnabled)} must be set when configuring auto-delete interval or trigger.",
                nameof(options));
        }

        if (options.Endpoints is null)
        {
            return;
        }

        var names = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
        foreach (var endpoint in options.Endpoints)
        {
            if (endpoint is null)
            {
                throw new ArgumentException("Endpoint options cannot contain null values.", nameof(options));
            }

            if (string.IsNullOrWhiteSpace(endpoint.Name))

View on GitHub (pinned to 25830f84bd)