App-vNext/Polly · error · ArgumentOutOfRangeException

Value must be greater than zero.

Error message

Value must be greater than zero.

What it means

AsyncBulkheadSyntax.BulkheadAsync throws ArgumentOutOfRangeException(nameof(maxParallelization)) when maxParallelization <= 0. The bulkhead needs at least one parallel execution slot to function; zero or negative capacity would reject every action. This is the legacy v7 Polly API guard.

Source

Thrown at src/Polly/Bulkhead/AsyncBulkheadSyntax.cs:65

    /// <summary>
    /// Builds a bulkhead isolation <see cref="Policy" />, which limits the maximum concurrency of actions executed through the policy.  Imposing a maximum concurrency limits the potential of governed actions, when faulting, to bring down the system.
    /// <para>When an execution would cause the number of actions executing concurrently through the policy to exceed <paramref name="maxParallelization" />, the policy allows a further <paramref name="maxQueuingActions" /> executions to queue, waiting for a concurrent execution slot.  When an execution would cause the number of queuing actions to exceed <paramref name="maxQueuingActions" />, a <see cref="BulkheadRejectedException" /> is thrown.</para>
    /// </summary>
    /// <param name="maxParallelization">The maximum number of concurrent actions that may be executing through the policy.</param>
    /// <param name="maxQueuingActions">The maximum number of actions that may be queuing, waiting for an execution slot.</param>
    /// <param name="onBulkheadRejectedAsync">An action to call asynchronously, if the bulkhead rejects execution due to oversubscription.</param>
    /// <returns>The policy instance.</returns>
    /// <exception cref="ArgumentOutOfRangeException">maxParallelization;Value must be greater than zero.</exception>
    /// <exception cref="ArgumentOutOfRangeException">maxQueuingActions;Value must be greater than or equal to zero.</exception>
    /// <exception cref="ArgumentNullException">Thrown when <paramref name="onBulkheadRejectedAsync"/> is <see langword="null"/>.</exception>
    public static AsyncBulkheadPolicy BulkheadAsync(
        int maxParallelization,
        int maxQueuingActions,
        Func<Context, Task> onBulkheadRejectedAsync)
    {
        if (maxParallelization <= 0)
        {
            throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero.");
        }

        if (maxQueuingActions < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), "Value must be greater than or equal to zero.");
        }

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

        return new AsyncBulkheadPolicy(
            maxParallelization,
            maxQueuingActions,
            onBulkheadRejectedAsync);
    }
}

View on GitHub (pinned to d0e46bdb1e)

Solutions

  1. Pass a positive integer for maxParallelization (typically the concurrency you want to allow).
  2. Guard config-derived values: maxParallelization = Math.Max(1, configured).
  3. Validate the config value at startup before constructing the policy.

Example fix

// before
var policy = Policy.BulkheadAsync(maxParallelization: 0, maxQueuingActions: 10);

// after
var policy = Policy.BulkheadAsync(maxParallelization: 10, maxQueuingActions: 10);
Defensive patterns

Strategy: validation

Validate before calling

if (maxParallelization <= 0) {
    throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Use a positive value.");
}
// then call Policy.BulkheadAsync(maxParallelization, ...)

Prevention

When it happens

Trigger: Calling Policy.BulkheadAsync(maxParallelization: 0, ...) or any negative value. Also when maxParallelization is computed from configuration that yields zero.

Common situations: Config bound to an int that defaults to 0 when missing; computing parallelization from a CPU count formula that rounds to zero on constrained hosts; passing an uninitialized int field (default 0).

Related errors


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