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 AdvancedCircuitBreakerAsync<T> (generic TResult) syntax when failureThreshold is zero or negative. failureThreshold is the failure ratio (0,1] for opening the circuit. Fires at policy construction time.
Source
Thrown at src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerTResultSyntax.cs:221
/// <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">failureThreshold;Value must be greater than zero.</exception>
/// <exception cref="ArgumentOutOfRangeException">failureThreshold;Value must be less than or equal to one.</exception>
/// <exception cref="ArgumentOutOfRangeException">samplingDuration;Value must be equal to or greater than the minimum resolution of the CircuitBreaker timer.</exception>
/// <exception cref="ArgumentOutOfRangeException">minimumThroughput;Value must be greater than one.</exception>
/// <exception cref="ArgumentOutOfRangeException">durationOfBreak;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<TResult> AdvancedCircuitBreakerAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, double failureThreshold, TimeSpan samplingDuration, int minimumThroughput, TimeSpan durationOfBreak, Action<DelegateResult<TResult>, 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
- Set failureThreshold to a ratio in (0,1] (e.g. 0.5).
- Validate the configured value is in (0,1] at startup.
- Guard against zero denominators when computing the ratio.
Example fix
// before
Policy.HandleResult<HttpResponseMessage>(r => !r.IsSuccessStatusCode)
.AdvancedCircuitBreakerAsync(
failureThreshold: 0,
samplingDuration: TimeSpan.FromSeconds(10),
minimumThroughput: 10,
durationOfBreak: TimeSpan.FromSeconds(30),
onBreak: (_, __, ___, ____) => { },
onReset: _ => { },
onHalfOpen: () => { });
// after
Policy.HandleResult<HttpResponseMessage>(r => !r.IsSuccessStatusCode)
.AdvancedCircuitBreakerAsync(
failureThreshold: 0.5,
...); Defensive patterns
Strategy: validation
Validate before calling
if (failureThreshold <= 0 || failureThreshold > 1)
throw new ArgumentOutOfRangeException(nameof(failureThreshold), "failureThreshold must be in (0,1]."); Type guard
static bool IsValidFailureThreshold(double t) => t > 0 && t <= 1;
Prevention
- Share a single options validator across all AdvancedCircuitBreaker overloads.
- Guard against zero denominators when computing the ratio at runtime.
- Treat the value as a ratio, not a percent.
When it happens
Trigger: Calling Policy.HandleResult<T>(...).AdvancedCircuitBreakerAsync(failureThreshold: 0, ...). The check is `failureThreshold <= 0`.
Common situations: Missing config defaulting to 0, or a dynamically computed ratio that yields 0.
Related errors
- Value must be less than or equal to one.
- Value must be greater than one.
- Value must be greater than zero.
- 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/0118e01f7cff0b01.
Report an issue: GitHub.