App-vNext/Polly · error · ArgumentOutOfRangeException

Value must be equal to or greater than {resolutionOfCircuit.

Error message

Value must be equal to or greater than {resolutionOfCircuit.TotalMilliseconds} milliseconds. This is the minimum resolution of the CircuitBreaker timer.

What it means

Thrown at policy-construction time by the legacy Polly v7 AdvancedCircuitBreaker when samplingDuration is smaller than the circuit breaker's internal timer resolution. The advanced breaker samples failures over fixed timeslices; the resolution is ResolutionOfCircuitTimer = 20ms, so samplingDuration must be at least 20 milliseconds. Below that, the sampling windows cannot be computed, hence ArgumentOutOfRangeException.

Source

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

        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)
        {
            throw new ArgumentOutOfRangeException(nameof(durationOfBreak), "Value must be greater than zero.");
        }

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

        if (onReset == null)

View on GitHub (pinned to d0e46bdb1e)

Solutions

  1. Set samplingDuration to at least 20ms; a practically useful value is in the hundreds of milliseconds to seconds range (e.g. TimeSpan.FromSeconds(10)).
  2. Validate configured samplingDuration against TimeSpan.FromMilliseconds(20) and fall back to a sane default.
  3. Check the unit of any value read from config (seconds vs milliseconds) before constructing the TimeSpan.

Example fix

// before
.AdvancedCircuitBreaker(0.5, TimeSpan.Zero, 10, TimeSpan.FromSeconds(30), ...);
// after
.AdvancedCircuitBreaker(0.5, TimeSpan.FromSeconds(10), 10, TimeSpan.FromSeconds(30), ...);
Defensive patterns

Strategy: validation

Validate before calling

var minResolution = TimeSpan.FromMilliseconds(20);
if (samplingDuration < minResolution) throw new ArgumentOutOfRangeException(nameof(samplingDuration), $"Must be >= {minResolution.TotalMilliseconds}ms.");
.AdvancedCircuitBreaker(failureThreshold, samplingDuration, minimumThroughput, durationOfBreak, onBreak, onReset, onHalfOpen);

Type guard

static bool IsSamplingDurationValid(TimeSpan d) => d >= TimeSpan.FromMilliseconds(20);

Prevention

When it happens

Trigger: Calling AdvancedCircuitBreaker/Async with samplingDuration less than 20ms (e.g. TimeSpan.Zero, TimeSpan.FromMilliseconds(1), or a negative/very small value).

Common situations: samplingDuration sourced from config that defaulted to 0 when the key was missing; a unit-conversion mistake (passing seconds where milliseconds were intended, or vice-versa, yielding a tiny value); passing TimeSpan.Zero by accident.

Related errors


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