App-vNext/Polly · error · ArgumentNullException

Value cannot be null.

Error message

Value cannot be null.

What it means

Thrown as ArgumentNullException(nameof(onBulkheadRejected)) from the generic Policy.Bulkhead<TResult>(maxParallelization, maxQueuingActions, onBulkheadRejected) overload when the rejection callback is null. The guard at BulkheadTResultSyntax.cs:69–72 fires at construction time.

Source

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

    /// <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. Use the two-parameter Policy.Bulkhead<TResult>(maxParallelization, maxQueuingActions) overload if no rejection callback is needed
  2. Pass a no-op lambda _ => { } when a callback is not required but the three-parameter overload is used
  3. Ensure the callback variable is non-null

Example fix

// before
var policy = Policy.Bulkhead<string>(10, 5, null); // throws

// after
var policy = Policy.Bulkhead<string>(10, 5); // two-parameter overload
// or:
var policy = Policy.Bulkhead<string>(10, 5, _ => { });
Defensive patterns

Strategy: validation

Validate before calling

Action<Context> safeOnReject = onBulkheadRejected ?? (_ => { });
var policy = Policy.Bulkhead<TResult>(maxParallelization, maxQueuingActions, safeOnReject);

Type guard

public static bool IsNonNullCallback(Action<Context> callback) => callback is not null;

Prevention

When it happens

Trigger: Calling Policy.Bulkhead<TResult>(maxParallelization, maxQueuingActions, null) — passing null as the onBulkheadRejected Action<Context>. The guard fires before the BulkheadPolicy<TResult> is constructed.

Common situations: Using the three-parameter generic overload when the two-parameter overload would suffice. Passing a callback variable that was conditionally set and ended up null. Migrating from a non-generic overload and forgetting to carry the callback.

Related errors


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