HangfireIO/Hangfire · error · ArgumentNullException
configuration
Error message
configuration
What it means
UseStorage registers a JobStorage and assigns JobStorage.Current. It throws ArgumentNullException(nameof(configuration)) at GlobalConfigurationExtensions.cs:38 when the receiver is null — the method needs the configuration both to register the storage and to return it for further chaining.
Source
Thrown at src/Hangfire.Core/GlobalConfigurationExtensions.cs:38
using Hangfire.Annotations;
using Hangfire.Common;
using Hangfire.Dashboard;
using Hangfire.Dashboard.Pages;
using Hangfire.Logging;
using Hangfire.Logging.LogProviders;
using Newtonsoft.Json;
namespace Hangfire
{
[EditorBrowsable(EditorBrowsableState.Never)]
public static class GlobalConfigurationExtensions
{
public static IGlobalConfiguration<TStorage> UseStorage<TStorage>(
[NotNull] this IGlobalConfiguration configuration,
[NotNull] TStorage storage)
where TStorage : JobStorage
{
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
if (storage == null) throw new ArgumentNullException(nameof(storage));
return configuration.Use(storage, static x => JobStorage.Current = x);
}
public static IGlobalConfiguration<TStorage> WithJobExpirationTimeout<TStorage>(
[NotNull] this IGlobalConfiguration<TStorage> configuration,
TimeSpan timeout)
where TStorage : JobStorage
{
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
configuration.Entry.JobExpirationTimeout = timeout;
return configuration;
}
public static IGlobalConfiguration<TActivator> UseActivator<TActivator>(
[NotNull] this IGlobalConfiguration configuration,View on GitHub (pinned to c236dd0f93)
Solutions
- Begin from GlobalConfiguration.Configuration (never-null singleton).
- Null-check any IGlobalConfiguration variable before chaining.
- Ensure the DI/factory providing the config never returns null.
- Compose the config chain in a single expression so no intermediate can be null.
Example fix
// before IGlobalConfiguration cfg = GetConfigOrNull(); cfg.UseStorage(new SqlServerStorage(cns)); // after GlobalConfiguration.Configuration.UseStorage(new SqlServerStorage(cns));
Defensive patterns
Strategy: validation
Validate before calling
GlobalConfiguration.Configuration.UseStorage(storage);
// or guard a captured variable:
if (configuration == null)
throw new ArgumentNullException(nameof(configuration));
if (storage == null)
throw new ArgumentNullException(nameof(storage));
configuration.UseStorage(storage); Type guard
static bool IsReady(IGlobalConfiguration? c, JobStorage? s) => c != null && s != null;
Prevention
- Always chain off GlobalConfiguration.Configuration.
- Null-check both configuration and storage before UseStorage.
- Configure storage once, early in startup, before any worker starts.
- Enable nullable reference types.
When it happens
Trigger: Calling .UseStorage(storage) on a null IGlobalConfiguration, e.g. ((IGlobalConfiguration)null).UseStorage(sqlStorage), or on a field whose DI assignment returned null.
Common situations: Forgetting to begin the chain from GlobalConfiguration.Configuration; a custom hosting extension that accepts IGlobalConfiguration but receives null; calling UseStorage before GlobalConfiguration is initialized.
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/9171ade6c976c521.
Report an issue: GitHub.