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 non-generic BulkheadPolicy via Policy.Bulkhead(...) with maxParallelization <= 0. The guard at BulkheadSyntax.cs:55–59 fires at policy construction time, before any semaphores are created. maxParallelization controls how many actions may execute concurrently through the bulkhead.
Source
Thrown at src/Polly/Bulkhead/BulkheadSyntax.cs:55
public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActions)
=> Bulkhead(maxParallelization, maxQueuingActions, EmptyAction);
/// <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="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 Bulkhead(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(
maxParallelization,
maxQueuingActions,
onBulkheadRejected);
}
View on GitHub (pinned to d0e46bdb1e)
Solutions
- Ensure the configuration value for maxParallelization is at least 1
- Add a fallback default when reading from configuration: config.GetValue("MaxParallel", 10)
- Validate the value at application startup and fail fast with a clear message
Example fix
// before
var maxPar = config.GetValue<int>("Bulkhead:MaxParallelization"); // 0 if missing
var policy = Policy.Bulkhead(maxPar, 10, _ => { }); // throws
// after
var maxPar = config.GetValue<int>("Bulkhead:MaxParallelization");
if (maxPar <= 0) maxPar = Environment.ProcessorCount;
var policy = Policy.Bulkhead(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(maxParallelization, maxQueuingActions, onReject); Type guard
public static bool IsValidParallelization(int value) => value > 0;
Prevention
- Validate configuration values at startup and fail fast with a descriptive message
- Use a named constant or configuration helper that enforces minimum values
- Log the effective bulkhead configuration at startup for diagnostics
When it happens
Trigger: Calling Policy.Bulkhead(maxParallelization, ...) where maxParallelization is 0 or negative. Common when the value comes from configuration that defaults to 0 or is computed from a formula that yields a non-positive result.
Common situations: Reading maxParallelization from appsettings.json where the key is missing (binds to default int 0). Calculating parallelization as a percentage of processor count with rounding to zero. Environment variable not set, parsing to 0.
Related errors
- Value must be greater than or equal to zero.
- Value must be greater than zero.
- Value must be greater than or equal to zero.
- Value cannot be null.
- Value cannot be null.
AI-assisted analysis of App-vNext/Polly@d0e46bdb1e (2026-08-13).
Data as JSON: /api/errors/6b77e5fb52030aea.
Report an issue: GitHub.