HangfireIO/Hangfire · error · ArgumentNullException

context

Error message

context

What it means

Thrown as ArgumentNullException by the obsolete RequestDispatcherContext.FromDashboardContext factory when the 'context' DashboardContext argument is null. The factory casts the context to OwinDashboardContext to extract options, storage, environment, and uri match; a null context has nothing to read, so it is rejected at line 53.

Source

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

            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)
        {
            if (context == null) throw new ArgumentNullException(nameof(context));

            var owinContext = context as OwinDashboardContext;
            if (owinContext == null)
            {
                throw new NotSupportedException($"context must be of type '{nameof(OwinDashboardContext)}'");
            }
            
            return new RequestDispatcherContext(
                owinContext.Options.AppPath,
                owinContext.Options.StatsPollingInterval,
                owinContext.Storage,
                owinContext.Environment,
                owinContext.UriMatch);
        }
    }
}

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Ensure any caller of FromDashboardContext (directly or via RequestDispatcherWrapper.Dispatch) supplies a non-null DashboardContext built from the current request.
  2. Migrate away from RequestDispatcherWrapper/RequestDispatcherContext to the modern IDashboardDispatcher model that receives a DashboardContext directly.
  3. Add a null guard in your dispatcher before calling the wrapper so the failure is reported at the true source.

Example fix

// before
wrapper.Dispatch(null);

// after
if (context == null) throw new ArgumentNullException(nameof(context));
wrapper.Dispatch(context);
Defensive patterns

Strategy: validation

Validate before calling

if (context == null) throw new ArgumentNullException(nameof(context));
wrapper.Dispatch(context);

Type guard

// if (context is not DashboardContext) return;

Prevention

When it happens

Trigger: Calling RequestDispatcherContext.FromDashboardContext(null) — i.e. a RequestDispatcherWrapper (or custom caller) passes a null DashboardContext to the conversion factory, often because the dispatcher's Dispatch was invoked with no context or the upstream pipeline lost the reference.

Common situations: A custom IDashboardDispatcher or middleware that forwards a null context into RequestDispatcherWrapper.Dispatch; a test that exercises the wrapper without building a real DashboardContext; a bug in pipeline wiring where the context is conditionally null.

Related errors


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