App-vNext/Polly · error · ArgumentOutOfRangeException

Value must be greater than zero.

Error message

Value must be greater than zero.

What it means

Thrown at policy-construction time by the legacy Polly v7 AdvancedCircuitBreaker when the failureThreshold (a proportion between 0 and 1) is less than or equal to 0. failureThreshold represents the failure ratio that trips the circuit (e.g. 0.5 = 50%); zero or negative means the breaker could never sensibly trigger, so Polly rejects it with ArgumentOutOfRangeException.

Source

Thrown at src/Polly/CircuitBreaker/AdvancedCircuitBreakerSyntax.cs:228

    /// <exception cref="ArgumentNullException">Thrown when <paramref name="onBreak"/> is <see langword="null"/>.</exception>
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="onReset"/> is <see langword="null"/>.</exception>
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="onHalfOpen"/> is <see langword="null"/>.</exception>
    /// <remarks>(see "Release It!" by Michael T. Nygard fi).</remarks>
    public static CircuitBreakerPolicy AdvancedCircuitBreaker(
        this PolicyBuilder policyBuilder,
        double failureThreshold,
        TimeSpan samplingDuration,
        int minimumThroughput,
        TimeSpan durationOfBreak,
        Action<Exception, CircuitState, TimeSpan, Context> onBreak,
        Action<Context> onReset,
        Action onHalfOpen)
    {
        var resolutionOfCircuit = TimeSpan.FromTicks(AdvancedCircuitController<EmptyStruct>.ResolutionOfCircuitTimer);

        if (failureThreshold <= 0)
        {
            throw new ArgumentOutOfRangeException(nameof(failureThreshold), "Value must be greater than zero.");
        }

        if (failureThreshold > 1)
        {
            throw new ArgumentOutOfRangeException(nameof(failureThreshold), "Value must be less than or equal to one.");
        }

        if (samplingDuration < resolutionOfCircuit)
        {
            throw new ArgumentOutOfRangeException(nameof(samplingDuration), $"Value must be equal to or greater than {resolutionOfCircuit.TotalMilliseconds} milliseconds. This is the minimum resolution of the CircuitBreaker timer.");
        }

        if (minimumThroughput <= 1)
        {
            throw new ArgumentOutOfRangeException(nameof(minimumThroughput), "Value must be greater than one.");
        }

        if (durationOfBreak < TimeSpan.Zero)

View on GitHub (pinned to d0e46bdb1e)

Solutions

  1. Set failureThreshold to a value strictly greater than 0 and at most 1 (e.g. 0.5 for 50%).
  2. If your config stores a percentage, divide by 100 before passing: configPercent / 100.0.
  3. Validate and fall back to a sane default (e.g. 0.5) when the configured value is non-positive.

Example fix

// before
.AdvancedCircuitBreaker(failureThreshold: 50, samplingDuration: ..., ...);
// after
.AdvancedCircuitBreaker(failureThreshold: 0.5, samplingDuration: ..., ...);
Defensive patterns

Strategy: validation

Validate before calling

if (!(failureThreshold > 0 && failureThreshold <= 1)) throw new ArgumentOutOfRangeException(nameof(failureThreshold), "failureThreshold must be in (0, 1].");
.AdvancedCircuitBreaker(failureThreshold, samplingDuration, minimumThroughput, durationOfBreak, onBreak, onReset, onHalfOpen);

Type guard

static bool IsFailureThresholdValid(double t) => t > 0 && t <= 1;

Prevention

When it happens

Trigger: Calling PolicyHandle.AdvancedCircuitBreaker(failureThreshold: 0 or negative, ...) or AdvancedCircuitBreakerAsync with the same. Also the typed-result variants. A computed percentage divided by 100 incorrectly (passing 0.5 as 50) or 0 default can trigger it.

Common situations: Configuring failureThreshold as a percentage (e.g. 50 for 50%) instead of a fraction (0.5); defaulting an unset threshold to 0; reading a 0 from config when the key was absent.

Related errors


AI-assisted analysis of App-vNext/Polly@d0e46bdb1e (2026-08-13). Data as JSON: /api/errors/fd08666057750724. Report an issue: GitHub.