HangfireIO/Hangfire · error · ArgumentNullException

jobStorage

Error message

jobStorage

What it means

Thrown as ArgumentNullException by the obsolete RequestDispatcherContext constructor when the 'jobStorage' JobStorage argument is null. The context carries the storage reference used by dashboard dispatchers to query job state; a null storage makes any dashboard data query impossible, so the constructor rejects it at line 34.

Source

Thrown at src/Hangfire.Core/Obsolete/RequestDispatcherContext.cs:34

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Hangfire.Annotations;

// ReSharper disable once CheckNamespace
namespace Hangfire.Dashboard
{
    [Obsolete("Use the `DashboardContext` class instead. Will be removed in 2.0.0.")]
    public class RequestDispatcherContext
    {
        public RequestDispatcherContext(
            string appPath,
            int statsPollingInterval,
            [NotNull] JobStorage jobStorage,
            [NotNull] IDictionary<string, object> owinEnvironment,
            [NotNull] Match uriMatch)
        {
            if (jobStorage == null) throw new ArgumentNullException(nameof(jobStorage));
            if (owinEnvironment == null) throw new ArgumentNullException(nameof(owinEnvironment));
            if (uriMatch == null) throw new ArgumentNullException(nameof(uriMatch));

            AppPath = appPath;
            StatsPollingInterval = statsPollingInterval;
            JobStorage = jobStorage;
            OwinEnvironment = owinEnvironment;
            UriMatch = uriMatch;
        }

        public string AppPath { get; }
        public int StatsPollingInterval { get; }
        public JobStorage JobStorage { get; }
        public IDictionary<string, object> OwinEnvironment { get; } 
        public Match UriMatch { get; }

        public static RequestDispatcherContext FromDashboardContext([NotNull] DashboardContext context)
        {

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Ensure JobStorage is configured via GlobalConfiguration.Configuration.UseXXXStorage(...) (or JobStorage.Current = ...) before the dashboard is mapped.
  2. Prefer the non-obsolete DashboardContext-based dispatchers over RequestDispatcherContext.
  3. If constructing RequestDispatcherContext manually, always forward a non-null JobStorage (e.g. JobStorage.Current).

Example fix

// before — dashboard mapped before storage is set
app.MapHangfireDashboard();
GlobalConfiguration.Configuration.UseSqlServerStorage(cs);

// after
GlobalConfiguration.Configuration.UseSqlServerStorage(cs);
app.UseHangfireDashboard();
Defensive patterns

Strategy: validation

Validate before calling

var storage = JobStorage.Current;
if (storage == null) throw new InvalidOperationException("Configure JobStorage before mapping the dashboard.");

Prevention

When it happens

Trigger: Constructing a RequestDispatcherContext with a null jobStorage — e.g. calling FromDashboardContext when the source OwinDashboardContext.Storage is null (storage never configured), or manually creating the context in tests/custom dispatchers without forwarding a JobStorage instance.

Common situations: Dashboard is wired before JobStorage.Current is set (so GlobalConfiguration.Configuration.UseStorage was not called, or called after the dashboard middleware); a custom OWIN host that builds the dashboard context without storage; tests that stub the dashboard pipeline incompletely.

Related errors


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