HangfireIO/Hangfire · error · ArgumentNullException
owinEnvironment
Error message
owinEnvironment
What it means
Thrown as ArgumentNullException by the obsolete RequestDispatcherContext constructor when the 'owinEnvironment' IDictionary<string,object> argument is null. The environment dictionary is the OWIN request environment that dispatchers read (path, user, etc.); a null environment makes request handling impossible, so the constructor rejects it at line 35.
Source
Thrown at src/Hangfire.Core/Obsolete/RequestDispatcherContext.cs:35
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)
{
if (context == null) throw new ArgumentNullException(nameof(context));View on GitHub (pinned to c236dd0f93)
Solutions
- Use the modern DashboardContext / IDashboardDispatcher pipeline instead of the obsolete RequestDispatcherContext, which ties you to OWIN.
- Ensure the OWIN environment dictionary is forwarded from the real IOwinContext.Environment when constructing the context.
- In ASP.NET Core hosting, use the AspNetCore Hangfire dashboard package rather than the OWIN-based context.
Example fix
// before — custom context with null environment var ctx = new RequestDispatcherContext(appPath, interval, storage, null, match); // after — forward the real OWIN environment var ctx = new RequestDispatcherContext(appPath, interval, storage, owinContext.Environment, match);
Defensive patterns
Strategy: validation
Validate before calling
if (owinEnvironment == null) throw new ArgumentNullException(nameof(owinEnvironment)); var ctx = new RequestDispatcherContext(appPath, interval, storage, owinContext.Environment, match);
Prevention
- Always forward the real IOwinContext.Environment, never null.
- In non-OWIN hosts, use the platform-native Hangfire dashboard package instead.
When it happens
Trigger: Constructing a RequestDispatcherContext with a null owinEnvironment — typically by calling FromDashboardContext when the source OwinDashboardContext.Environment is null (custom/mis-wired dashboard context), or by manually creating the context without forwarding the OWIN environment.
Common situations: A non-OWIN host (e.g. ASP.NET Core) accidentally routed through the OWIN-only RequestDispatcherContext path; a test or custom middleware that builds a dashboard context with a null environment dictionary; a malformed OWIN pipeline where the environment wasn't propagated.
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/0150e578e883ac40.
Report an issue: GitHub.