HangfireIO/Hangfire · error · ArgumentNullException
filterProvider
Error message
filterProvider
What it means
Thrown by the internal BackgroundJobFactory constructor when filterProvider is null. BackgroundJobFactory decorates a CoreBackgroundJobFactory and resolves IClientFilter instances through IJobFilterProvider before job creation. This guard ensures the filter-discovery step (GetFilters -> _filterProvider.GetFilters(job)) never dereferences null. The internal constructor is used by the public constructor that defaults to JobFilterProviders.Providers and wires a StateMachine.
Source
Thrown at src/Hangfire.Core/Client/BackgroundJobFactory.cs:65
return factory.RetryAttempts;
}
return 0;
}
set
{
if (_innerFactory is CoreBackgroundJobFactory factory)
{
factory.RetryAttempts = value;
}
}
}
internal BackgroundJobFactory(
[NotNull] IJobFilterProvider filterProvider,
[NotNull] IBackgroundJobFactory innerFactory)
{
if (filterProvider == null) throw new ArgumentNullException(nameof(filterProvider));
if (innerFactory == null) throw new ArgumentNullException(nameof(innerFactory));
_filterProvider = filterProvider;
_innerFactory = innerFactory;
}
public IStateMachine StateMachine => _innerFactory.StateMachine;
public BackgroundJob Create(CreateContext context)
{
if (context == null) throw new ArgumentNullException(nameof(context));
var filterInfo = GetFilters(context.Job);
try
{
context.Factory = this;
View on GitHub (pinned to c236dd0f93)
Solutions
- Use the parameterless BackgroundJobFactory() constructor or the public one accepting IJobFilterProvider — never the internal constructor.
- Register a concrete IJobFilterProvider (e.g., JobFilterProviders.Providers) in your DI container.
- In tests, pass a mock/fake IJobFilterProvider (e.g., new EmptyFilterProvider() or JobFilterProviders.Providers).
Example fix
// before var factory = new BackgroundJobFactory(null); // after var factory = new BackgroundJobFactory(); // uses JobFilterProviders.Providers // or explicitly: var factory = new BackgroundJobFactory(JobFilterProviders.Providers);
Defensive patterns
Strategy: validation
Validate before calling
var provider = filterProvider ?? JobFilterProviders.Providers; var factory = new BackgroundJobFactory(provider);
Type guard
public static bool IsValidFilterProvider(IJobFilterProvider p)
=> p != null; Prevention
- Prefer the parameterless BackgroundJobFactory() constructor in DI registrations.
- Register IJobFilterProvider as a singleton pointing at JobFilterProviders.Providers or a scoped provider.
- Avoid the internal constructor outside of Hangfire's own assemblies.
When it happens
Trigger: Calling the internal BackgroundJobFactory(IJobFilterProvider, IBackgroundJobFactory) constructor (via reflection or a friend assembly) with a null filterProvider; a custom IBackgroundJobFactory wrapper that forwards a null provider.
Common situations: Subclassing or wrapping BackgroundJobFactory with dependency injection containers that fail to resolve IJobFilterProvider; test fixtures that pass null instead of JobFilterProviders.Providers or a mock provider.
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/4ab0928ac8d1e90f.
Report an issue: GitHub.