microsoft/aspire · error · ArgumentException

Endpoint options cannot contain null values.

Error message

Endpoint options cannot contain null values.

What it means

ValidateSandboxOptions in PublishAsAzureSandbox rejects an endpoint options collection that contains a null entry. The library requires every element of AzureSandboxOptions.Endpoints to be a fully populated endpoint descriptor; nulls indicate a half-initialized options object that would produce broken Azure sandbox endpoint configuration.

Solutions

  1. Remove null entries from options.Endpoints before calling PublishAsAzureSandbox
  2. Ensure any endpoint factory/deserialization code never emits null elements
  3. Validate options in your own code with Endpoints.All(e => e is not null) before publishing

Example fix

// before
var options = new AzureSandboxOptions { Endpoints = [null, endpointA] };
builder.PublishAsAzureSandbox(resource, options);
// after
var options = new AzureSandboxOptions { Endpoints = [endpointA] };
builder.PublishAsAzureSandbox(resource, options);
Defensive patterns

Strategy: validation

Validate before calling

if (options.Endpoints.Any(e => e is null)) throw new ArgumentException("Endpoints must not contain nulls");

Type guard

bool HasNoNullEndpoints(AzureSandboxOptions o) => o.Endpoints.All(e => e is not null);

Prevention

When it happens

Trigger: Calling PublishAsAzureSandbox with options whose Endpoints list literally contains null, e.g. new AzureSandboxOptions { Endpoints = [null] } or building the list programmatically where a null endpoint slipped in.

Common situations: Conditional endpoint construction where a variable assigned from config or a factory returns null; array initializers with placeholder nulls to be filled later; deserialization of options from JSON where a null element was preserved.

Related errors


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

Appendix: source

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

        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))
            {
                throw new ArgumentException("Endpoint option names cannot be empty.", nameof(options));
            }

            if (!names.Add(endpoint.Name))
            {
                throw new ArgumentException($"Endpoint option '{endpoint.Name}' is configured more than once.", nameof(options));
            }
        }
    }

    private static void ValidateOptionalWholeSecondDuration(TimeSpan? value, string paramName, TimeSpan? maximum = null)
    {
        if (value is null)
        {

View on GitHub (pinned to 25830f84bd)