HangfireIO/Hangfire · error · ArgumentNullException
configuration
Error message
configuration
What it means
The UseSqlServerStorage(this IGlobalConfiguration, string) extension method received a null configuration argument. This is a standard ArgumentNullException guard; configuration is the 'this' parameter of the extension method, so calling it on null is the cause.
Source
Thrown at src/Hangfire.SqlServer/SqlServerStorageExtensions.cs:33
using System;
using System.Data.Common;
using System.Threading;
using Hangfire.Annotations;
using Hangfire.SqlServer;
// ReSharper disable once CheckNamespace
namespace Hangfire
{
public static class SqlServerStorageExtensions
{
private static int _metricsInitialized;
public static IGlobalConfiguration<SqlServerStorage> UseSqlServerStorage(
[NotNull] this IGlobalConfiguration configuration,
[NotNull] string nameOrConnectionString)
{
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
if (nameOrConnectionString == null) throw new ArgumentNullException(nameof(nameOrConnectionString));
var storage = new SqlServerStorage(nameOrConnectionString);
return configuration.UseStorage(storage).UseSqlServerStorageCommonMetrics();
}
public static IGlobalConfiguration<SqlServerStorage> UseSqlServerStorage(
[NotNull] this IGlobalConfiguration configuration,
[NotNull] string nameOrConnectionString,
[NotNull] SqlServerStorageOptions options)
{
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
if (nameOrConnectionString == null) throw new ArgumentNullException(nameof(nameOrConnectionString));
if (options == null) throw new ArgumentNullException(nameof(options));
var storage = new SqlServerStorage(nameOrConnectionString, options);
return configuration.UseStorage(storage).UseSqlServerStorageCommonMetrics();
}View on GitHub (pinned to c236dd0f93)
Solutions
- Ensure you start the fluent chain from GlobalConfiguration.Configuration (Hangfire's static entry point).
- Verify the configuration variable is non-null before chaining.
- Follow the documented startup pattern: GlobalConfiguration.Configuration.UseSqlServerStorage(...).
Example fix
// before
IGlobalConfiguration config = null;
config.UseSqlServerStorage("HangfireDB");
// after
GlobalConfiguration.Configuration
.UseSqlServerStorage("HangfireDB")
.UseConsole(); Defensive patterns
Strategy: validation
Validate before calling
var config = GlobalConfiguration.Configuration; // ensure non-null entry point
if (config == null)
throw new InvalidOperationException("GlobalConfiguration.Configuration is not initialized.");
config.UseSqlServerStorage(nameOrConnectionString); Prevention
- Always start the configuration chain from GlobalConfiguration.Configuration.
- Do not store IGlobalConfiguration in a variable that may be null; chain directly.
- Place UseSqlServerStorage early in your application startup sequence.
When it happens
Trigger: Calling null.UseSqlServerStorage(nameOrConnectionString) where the IGlobalConfiguration instance is null; chaining UseSqlServerStorage before GlobalConfiguration.Configuration is assigned.
Common situations: Calling configuration extensions before var config = GlobalConfiguration.Configuration; in startup code ordering mistakes; refactoring that removes the configuration variable.
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/2004328c25c00f15.
Report an issue: GitHub.