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 Polly AdvancedCircuitBreaker<T> syntax when the failureThreshold argument is zero or negative. failureThreshold is the failure ratio (0,1] at which the advanced circuit opens, so any value <= 0 is meaningless. The guard fires at policy BUILD time (inside the syntax extension), not when the policy executes.
Source
Thrown at src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.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<TResult> AdvancedCircuitBreaker<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 strictly greater than 0 and at most 1, e.g. 0.5 for 50%.
- If the value comes from configuration, validate it is in (0,1] before passing it to the policy.
- When computing a ratio dynamically, guard against a zero denominator before division.
Example fix
// before
Policy.Handle<HttpRequestException>()
.AdvancedCircuitBreaker(
failureThreshold: 0,
samplingDuration: TimeSpan.FromSeconds(10),
minimumThroughput: 10,
durationOfBreak: TimeSpan.FromSeconds(30),
onBreak: (_, __, ___, ____) => { },
onReset: _ => { },
onHalfOpen: () => { });
// after
Policy.Handle<HttpRequestException>()
.AdvancedCircuitBreaker(
failureThreshold: 0.5,
samplingDuration: TimeSpan.FromSeconds(10),
minimumThroughput: 10,
durationOfBreak: TimeSpan.FromSeconds(30),
onBreak: (_, __, ___, ____) => { },
onReset: _ => { },
onHalfOpen: () => { }); 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
- Centralize circuit-breaker construction behind a factory that validates all inputs once.
- Bind failureThreshold through a strongly-typed options object validated at startup.
- Treat failureThreshold as a ratio, never a percentage or count.
When it happens
Trigger: Calling Policy.Handle<...>().AdvancedCircuitBreaker(failureThreshold: 0, ...) or AdvancedCircuitBreaker(failureThreshold: -0.5, ...). The check is `failureThreshold <= 0`.
Common situations: Configuring the threshold from a config file where the value is missing/defaulted to 0, or computing it as failures/total when total is 0 (yielding 0). Passing an integer literal 0 where a percentage was intended (e.g. thinking 0 means 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 less than or equal to one.
- Value must be greater than one.
AI-assisted analysis of App-vNext/Polly@d0e46bdb1e (2026-08-13).
Data as JSON: /api/errors/d3dc9e732cd1c861.
Report an issue: GitHub.