App-vNext/Polly · error · ArgumentOutOfRangeException

Value must be greater than zero.

Error message

Value must be greater than zero.

What it means

Thrown as ArgumentOutOfRangeException(nameof(maxParallelization)) when constructing a generic BulkheadPolicy<TResult> via Policy.Bulkhead<TResult>(...) with maxParallelization <= 0. The guard at BulkheadTResultSyntax.cs:59–63 fires at construction time. This is the generic overload for result-returning bulkhead policies.

Source

Thrown at src/Polly/Bulkhead/BulkheadTResultSyntax.cs:59

        => Bulkhead<TResult>(maxParallelization, maxQueuingActions, EmptyAction);

    /// <summary>
    /// Builds a bulkhead isolation <see cref="Policy{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="onBulkheadRejected">An action to call, 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="onBulkheadRejected"/> is <see langword="null"/>.</exception>
    public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization, int maxQueuingActions, Action<Context> onBulkheadRejected)
    {
        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 (onBulkheadRejected == null)
        {
            throw new ArgumentNullException(nameof(onBulkheadRejected));
        }

        return new BulkheadPolicy<TResult>(
            maxParallelization,
            maxQueuingActions,
            onBulkheadRejected);
    }
}

View on GitHub (pinned to d0e46bdb1e)

Solutions

  1. Ensure maxParallelization is at least 1 when constructing the typed bulkhead policy
  2. Provide a fallback default when reading from configuration
  3. Validate at startup and log a clear error before the policy is built

Example fix

// before
var maxPar = int.Parse(config["MaxParallel"]); // 0 if misconfigured
var policy = Policy.Bulkhead<string>(maxPar, 10, _ => { }); // throws

// after
var maxPar = int.TryParse(config["MaxParallel"], out var p) && p > 0 ? p : 10;
var policy = Policy.Bulkhead<string>(maxPar, 10, _ => { });
Defensive patterns

Strategy: validation

Validate before calling

if (maxParallelization <= 0)
{
    throw new InvalidOperationException($"Invalid maxParallelization: {maxParallelization}. Must be >= 1.");
}
var policy = Policy.Bulkhead<TResult>(maxParallelization, maxQueuingActions, onReject);

Type guard

public static bool IsValidParallelization(int value) => value > 0;

Prevention

When it happens

Trigger: Calling Policy.Bulkhead<TResult>(maxParallelization, ...) where maxParallelization is 0 or negative. Identical validation to the non-generic overload, but for the typed-return bulkhead.

Common situations: Configuration binding to a missing key that defaults to int 0. Formula computing processor-based parallelization that rounds to zero. Copy-paste of a configuration value from a different setting that was 0.

Related errors


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