HangfireIO/Hangfire · error · ArgumentNullException

nameOrConnectionString

Error message

nameOrConnectionString

What it means

The UseSqlServerStorage(this IGlobalConfiguration, string, SqlServerStorageOptions) extension method received a null nameOrConnectionString argument. This is a standard ArgumentNullException guard for the connection-string parameter.

Source

Thrown at src/Hangfire.SqlServer/SqlServerStorageExtensions.cs:46

        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();
        }

        public static IGlobalConfiguration<SqlServerStorage> UseSqlServerStorage(
            [NotNull] this IGlobalConfiguration configuration,
            [NotNull] Func<DbConnection> connectionFactory)
        {
            if (configuration == null) throw new ArgumentNullException(nameof(configuration));
            if (connectionFactory == null) throw new ArgumentNullException(nameof(connectionFactory));

            var storage = new SqlServerStorage(connectionFactory);
            return configuration.UseStorage(storage).UseSqlServerStorageCommonMetrics();
        }

        public static IGlobalConfiguration<SqlServerStorage> UseSqlServerStorage(

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Ensure nameOrConnectionString is a non-null string (either a raw connection string or a config name).
  2. Validate the value from configuration before passing, providing a fallback or error if missing.

Example fix

// before
var conn = Configuration.GetValue<string>("Hangfire:ConnectionString"); // null if missing
config.UseSqlServerStorage(conn, options);
// after
var conn = Configuration.GetConnectionString("Hangfire")
    ?? throw new InvalidOperationException("Hangfire connection string not configured");
config.UseSqlServerStorage(conn, options);
Defensive patterns

Strategy: validation

Validate before calling

string nameOrConnectionString = Configuration.GetConnectionString("Hangfire")
    ?? throw new InvalidOperationException("Hangfire connection string not configured.");

config.UseSqlServerStorage(nameOrConnectionString, options);

Type guard

static bool IsValidConnectionStringArg(string value) => !string.IsNullOrWhiteSpace(value);

Prevention

When it happens

Trigger: Passing null as the nameOrConnectionString to the three-parameter UseSqlServerStorage overload; a config value that resolved to null.

Common situations: Reading a connection string name from IConfiguration that is absent; uninitialized variable; refactoring that removes the assignment.

Related errors


AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13). Data as JSON: /api/errors/ec3eb26e72e38eda. Report an issue: GitHub.