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 async CircuitBreakerAsync syntax (non-generic) when exceptionsAllowedBeforeBreaking is <= 0. This is the count of handled exceptions permitted before the simple circuit opens; it must be at least 1. Fires at policy construction.
Source
Thrown at src/Polly/CircuitBreaker/AsyncCircuitBreakerSyntax.cs:183
/// </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 AsyncCircuitBreakerPolicy CircuitBreakerAsync(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
- Set exceptionsAllowedBeforeBreaking to at least 1 (commonly 3-10).
- Validate the configured count is a positive integer at startup.
- Use 1 if you want the circuit to open on the first handled exception.
Example fix
// before
Policy.Handle<HttpRequestException>()
.CircuitBreakerAsync(
exceptionsAllowedBeforeBreaking: 0,
durationOfBreak: TimeSpan.FromSeconds(30),
onBreak: (_, __, ___, ____) => { },
onReset: _ => { },
onHalfOpen: () => { });
// after
Policy.Handle<HttpRequestException>()
.CircuitBreakerAsync(
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
- Use 1 when you want the circuit to open on the first handled exception.
- Bind the count from a validated options object.
- Fail fast at startup if config yields a non-positive integer.
When it happens
Trigger: Calling Policy.Handle<...>().CircuitBreakerAsync(exceptionsAllowedBeforeBreaking: 0, ...). The check is `exceptionsAllowedBeforeBreaking <= 0`.
Common situations: Passing 0 from missing/blank config, or intending 'always break' but using 0 instead of 1.
Related errors
- Value must be greater than zero.
- Value must be less than or equal to one.
- Value must be greater than one.
- Value must be greater than zero.
- Value must be less than or equal to one.
AI-assisted analysis of App-vNext/Polly@d0e46bdb1e (2026-08-13).
Data as JSON: /api/errors/563e929e2b12d3e7.
Report an issue: GitHub.