HangfireIO/Hangfire · error · ArgumentNullException
execution
Error message
execution
What it means
Thrown by BackgroundDispatcherAsync's constructor (internal) when the IBackgroundExecution argument is null. The dispatcher delegates all work (RunAsync) to that execution, so a null instance has nothing to drive.
Source
Thrown at src/Hangfire.Core/Processing/BackgroundDispatcherAsync.cs:49
private readonly IBackgroundExecution _execution;
private readonly Func<Guid, object, Task> _action;
private readonly object _state;
private readonly TaskScheduler _taskScheduler;
private readonly bool _ownsScheduler;
public BackgroundDispatcherAsync(
[NotNull] IBackgroundExecution execution,
[NotNull] Func<Guid, object, Task> action,
[CanBeNull] object state,
[NotNull] TaskScheduler taskScheduler,
int maxConcurrency,
bool ownsScheduler)
{
if (maxConcurrency <= 0) throw new ArgumentOutOfRangeException(nameof(maxConcurrency));
_execution = execution ?? throw new ArgumentNullException(nameof(execution));
_action = action ?? throw new ArgumentNullException(nameof(action));
_state = state;
_taskScheduler = taskScheduler ?? throw new ArgumentNullException(nameof(taskScheduler));
_ownsScheduler = ownsScheduler;
#if !NETSTANDARD1_3
AppDomainUnloadMonitor.EnsureInitialized();
#endif
_stopped = new CountdownEvent(maxConcurrency);
for (var i = 0; i < maxConcurrency; i++)
{
Task.Factory.StartNew(
DispatchLoop,
CancellationToken.None,
TaskCreationOptions.None,
_taskScheduler).Unwrap();View on GitHub (pinned to c236dd0f93)
Solutions
- Ensure a non-null IBackgroundExecution (BackgroundExecution instance) is created and passed.
- Guard the call site with a null check and fail fast with a clearer message before reaching the constructor.
- Verify the dependency-injection registration that supplies the execution is active and not returning null.
Example fix
// before
var dispatcher = new BackgroundDispatcherAsync(null, action, state, scheduler, 4, false);
// after
var execution = execution ?? throw new InvalidOperationException("Execution must be initialized before the dispatcher.");
var dispatcher = new BackgroundDispatcherAsync(execution, action, state, scheduler, 4, false); Defensive patterns
Strategy: validation
Validate before calling
if (execution == null) throw new InvalidOperationException("IBackgroundExecution must be created before the dispatcher."); Prevention
- Construct the BackgroundExecution before the dispatcher that consumes it.
- Verify DI registrations resolve the execution service.
- Fail fast at startup with a clear message rather than letting null propagate.
When it happens
Trigger: Constructing BackgroundDispatcherAsync with execution == null. Internal wiring that failed to create/resolve the BackgroundExecution dependency before building the dispatcher.
Common situations: DI/registration defect where the execution instance was not created; a null propagated from a factory method that returned null on a missing storage dependency; unit test stubbing that forgot to supply the execution.
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/e253e8f15858e216.
Report an issue: GitHub.