App-vNext/Polly · error · ArgumentOutOfRangeException

Value must be greater than zero.

Error message

Value must be greater than zero.

What it means

Thrown by the legacy v7 sync CircuitBreaker syntax (non-generic) when exceptionsAllowedBeforeBreaking is <= 0. This is the number of handled exceptions permitted before the simple circuit opens; it must be at least 1. Fires at policy construction time (not when the policy runs).

Source

Thrown at src/Polly/CircuitBreaker/CircuitBreakerSyntax.cs:182

    /// </para>
    /// </summary>
    /// <param name="policyBuilder">The policy builder.</param>
    /// <param name="exceptionsAllowedBeforeBreaking">The number of exceptions that are allowed before opening the circuit.</param>
    /// <param name="durationOfBreak">The duration the circuit will stay open before resetting.</param>
    /// <param name="onBreak">The action to call when the circuit transitions to an <see cref="CircuitState.Open"/> state.</param>
    /// <param name="onReset">The action to call when the circuit resets to a <see cref="CircuitState.Closed"/> state.</param>
    /// <param name="onHalfOpen">The action to call when the circuit transitions to <see cref="CircuitState.HalfOpen"/> state, ready to try action executions again. </param>
    /// <returns>The policy instance.</returns>
    /// <remarks>(see "Release It!" by Michael T. Nygard fi).</remarks>
    /// <exception cref="ArgumentOutOfRangeException">exceptionsAllowedBeforeBreaking;Value must be greater than zero.</exception>
    /// <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>
    public static CircuitBreakerPolicy CircuitBreaker(this PolicyBuilder policyBuilder, int exceptionsAllowedBeforeBreaking, TimeSpan durationOfBreak, Action<Exception, CircuitState, TimeSpan, Context> onBreak, Action<Context> onReset, Action onHalfOpen)
    {
        if (exceptionsAllowedBeforeBreaking <= 0)
        {
            throw new ArgumentOutOfRangeException(nameof(exceptionsAllowedBeforeBreaking), "Value must be greater than zero.");
        }

        if (durationOfBreak < TimeSpan.Zero)
        {
            throw new ArgumentOutOfRangeException(nameof(durationOfBreak), "Value must be greater than zero.");
        }

        if (onBreak == null)
        {
            throw new ArgumentNullException(nameof(onBreak));
        }

        if (onReset == null)
        {
            throw new ArgumentNullException(nameof(onReset));
        }

        if (onHalfOpen == null)

View on GitHub (pinned to d0e46bdb1e)

Solutions

  1. Set exceptionsAllowedBeforeBreaking to at least 1 (commonly 3-10).
  2. Validate the configured value is a positive integer at startup.
  3. Use 1 if you want the circuit to open on the first handled exception.

Example fix

// before
Policy.Handle<HttpRequestException>()
    .CircuitBreaker(
        exceptionsAllowedBeforeBreaking: 0,
        durationOfBreak: TimeSpan.FromSeconds(30),
        onBreak: (_, __, ___, ____) => { },
        onReset: _ => { },
        onHalfOpen: () => { });

// after
Policy.Handle<HttpRequestException>()
    .CircuitBreaker(
        exceptionsAllowedBeforeBreaking: 5,
        durationOfBreak: TimeSpan.FromSeconds(30),
        onBreak: (_, __, ___, ____) => { },
        onReset: _ => { },
        onHalfOpen: () => { });
Defensive patterns

Strategy: validation

Validate before calling

if (exceptionsAllowedBeforeBreaking <= 0)
    throw new ArgumentOutOfRangeException(nameof(exceptionsAllowedBeforeBreaking), "Must be >= 1.");

Type guard

static bool IsValidExceptionsAllowed(int n) => n >= 1;

Prevention

When it happens

Trigger: Calling Policy.Handle<...>().CircuitBreaker(exceptionsAllowedBeforeBreaking: 0, ...). The check is `exceptionsAllowedBeforeBreaking <= 0`.

Common situations: Passing 0 from missing/blank configuration, or intending 'always open' but using 0 instead of 1.

Related errors


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