App-vNext/Polly · error · ArgumentNullException

Value cannot be null.

Error message

Value cannot be null.

What it means

AsyncBulkheadSyntax.BulkheadAsync throws ArgumentNullException(nameof(onBulkheadRejectedAsync)) when the rejection callback is null. The bulkhead invokes this callback when an action is rejected due to all slots and queue being full, so a null handler would NRE at rejection time; the constructor rejects it eagerly.

Source

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

    /// <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. Use the 2-argument overload Policy.BulkheadAsync(maxParallelization, maxQueuingActions) which supplies a default no-op handler.
  2. If using the 3-argument overload, pass a non-null Func<Context, Task> (e.g. _ => Task.CompletedTask).

Example fix

// before
var policy = Policy.BulkheadAsync(5, 10, null);

// after
var policy = Policy.BulkheadAsync(5, 10); // uses default handler
Defensive patterns

Strategy: validation

Validate before calling

if (onBulkheadRejectedAsync == null) {
    // use the 2-arg overload instead, or supply a no-op:
    onBulkheadRejectedAsync = _ => Task.CompletedTask;
}

Prevention

When it happens

Trigger: Calling the 3-argument Policy.BulkheadAsync(maxParallelization, maxQueuingActions, null) overload with a null callback.

Common situations: Using the explicit-callback overload by mistake when you do not need a custom handler; passing a field that was never assigned; refactoring that dropped the callback argument.

Related errors


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