microsoft/aspire · error · InvalidOperationException

exceeds the maximum supported ADC interval.

Error message

{propertyName} exceeds the maximum supported ADC interval.

What it means

ADC lifecycle policy intervals are stored as 32-bit second counts; ToInt32Seconds throws InvalidOperationException when the supplied TimeSpan exceeds int.MaxValue seconds (~68 years) — practically signaling a nonsensical or mis-scaled interval for an ADC property.

Solutions

  1. Reduce the interval to a realistic value (seconds to days range) appropriate for the ADC policy.
  2. Check unit scaling of the incoming config value; fix any accidental multiplier.
  3. If a genuinely large duration is required, use a property/overload accepting int64 seconds (ToInt64Seconds path).

Example fix

// before
policy.Retention = TimeSpan.FromTicks(TimeSpan.TicksPerDay * 10000000); // absurd
// after
policy.Retention = TimeSpan.FromDays(30);
Defensive patterns

Strategy: validation

Validate before calling

static TimeSpan ClampToInt32Seconds(TimeSpan t) =>
    t.TotalSeconds > int.MaxValue ? TimeSpan.FromSeconds(int.MaxValue) : t;

Try / catch

try { policy.Retention = parsed; }
catch (InvalidOperationException ex) when (ex.Message.Contains("maximum supported ADC interval"))
{ /* fix unit scaling of the source value, then retry */ }

Prevention

When it happens

Trigger: Passing a TimeSpan larger than 2,147,483,647 seconds (e.g. TimeSpan.MaxValue, or a value accidentally multiplied by 1000) to a CreateLifecyclePolicy property backed by ToInt32Seconds.

Common situations: Unit confusion such as treating the config value as milliseconds but constructing TimeSpan.FromSeconds, or reading an unbounded/garbage value from configuration.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxContainerDeployment.cs:621

        };
    }

    private static int? ToInt32Seconds(TimeSpan? value, string propertyName)
    {
        if (value is null)
        {
            return null;
        }

        if (value < TimeSpan.Zero || value.Value.Ticks % TimeSpan.TicksPerSecond != 0)
        {
            throw new InvalidOperationException($"{propertyName} must be a non-negative whole-second duration.");
        }

        var seconds = value.Value.Ticks / TimeSpan.TicksPerSecond;
        return seconds <= int.MaxValue
            ? (int)seconds
            : throw new InvalidOperationException($"{propertyName} exceeds the maximum supported ADC interval.");
    }

    private static long? ToInt64Seconds(TimeSpan? value, string propertyName)
    {
        if (value is null)
        {
            return null;
        }

        if (value < TimeSpan.Zero || value.Value.Ticks % TimeSpan.TicksPerSecond != 0)
        {
            throw new InvalidOperationException($"{propertyName} must be a non-negative whole-second duration.");
        }

        return value.Value.Ticks / TimeSpan.TicksPerSecond;
    }

    private static async Task<AzureDevComputeDiskImage> CreateDiskImageAsync(

View on GitHub (pinned to 25830f84bd)