App-vNext/Polly · error · ArgumentNullException
Value cannot be null.
Error message
Value cannot be null.
What it means
AsyncBulkheadTResultSyntax.BulkheadAsync<TResult> throws ArgumentNullException(nameof(onBulkheadRejectedAsync)) when the rejection callback is null. Same rationale as the non-generic overload: the callback runs on rejection, so a null one is rejected at construction rather than failing later.
Source
Thrown at src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs:68
/// <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);
}
private static Task EmptyHandler(Context context) => TaskHelper.EmptyTask;
}
View on GitHub (pinned to d0e46bdb1e)
Solutions
- Use the 2-argument overload Policy<T>.BulkheadAsync(maxParallelization, maxQueuingActions) to get the default handler.
- If using the 3-argument overload, pass a non-null Func<Context, Task>.
Example fix
// before var policy = Policy<string>.BulkheadAsync(5, 10, null); // after var policy = Policy<string>.BulkheadAsync(5, 10); // default handler
Defensive patterns
Strategy: validation
Validate before calling
if (onBulkheadRejectedAsync == null) {
// prefer the 2-arg overload; otherwise supply a no-op:
onBulkheadRejectedAsync = _ => Task.CompletedTask;
} Prevention
- Use the 2-argument Policy<T>.BulkheadAsync overload unless you need a custom handler.
- When using the 3-argument overload, always pass a non-null callback.
- Static-analyze for null literals in callback positions.
When it happens
Trigger: Calling Policy<T>.BulkheadAsync(maxParallelization, maxQueuingActions, null).
Common situations: Reaching for the 3-argument overload without wanting a custom handler; passing an unassigned field; refactoring that removed the callback.
Related errors
- Value cannot be null.
- Value must be greater than zero.
- Value must be greater than or equal to zero.
- Value must be greater than zero.
- Value must be greater than or equal to zero.
AI-assisted analysis of App-vNext/Polly@d0e46bdb1e (2026-08-13).
Data as JSON: /api/errors/faf533716c7164e7.
Report an issue: GitHub.