App-vNext/Polly · error · ArgumentOutOfRangeException

Value must be greater than zero.

Error message

Value must be greater than zero.

What it means

AsyncBulkheadTResultSyntax.BulkheadAsync<TResult> throws ArgumentOutOfRangeException(nameof(maxParallelization)) when maxParallelization <= 0. This is the generic legacy v7 bulkhead policy; like the non-generic overload it requires at least one parallel slot.

Source

Thrown at src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs:58

        => BulkheadAsync<TResult>(maxParallelization, maxQueuingActions, EmptyHandler);

    /// <summary>
    /// Builds a bulkhead isolation <see cref="AsyncPolicy{TResult}" />, 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>
    /// <typeparam name="TResult">The type of the result.</typeparam>
    /// <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<TResult> BulkheadAsync<TResult>(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<TResult>(
            maxParallelization,
            maxQueuingActions,
            onBulkheadRejectedAsync);
    }

View on GitHub (pinned to d0e46bdb1e)

Solutions

  1. Pass a positive maxParallelization.
  2. Clamp derived values with Math.Max(1, value).
  3. Validate config at startup.

Example fix

// before
var policy = Policy<string>.BulkheadAsync(maxParallelization: 0, maxQueuingActions: 5);

// after
var policy = Policy<string>.BulkheadAsync(maxParallelization: 5, maxQueuingActions: 5);
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Calling Policy<T>.BulkheadAsync(maxParallelization: 0, ...) or any non-positive value when constructing a result-typed bulkhead.

Common situations: Config bound to a default-zero int; formula-derived concurrency that underflows to zero; uninitialized field.

Related errors


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