HangfireIO/Hangfire · error · NotSupportedException
context must be of type 'OwinDashboardContext'
Error message
context must be of type 'OwinDashboardContext'
What it means
Thrown as NotSupportedException (message 'context must be of type OwinDashboardContext') by RequestDispatcherContext.FromDashboardContext when the supplied DashboardContext is not an OwinDashboardContext. The obsolete factory relies on OWIN-specific properties (Options, Storage, Environment, UriMatch) that only exist on OwinDashboardContext; any other DashboardContext subclass cannot provide them.
Source
Thrown at src/Hangfire.Core/Obsolete/RequestDispatcherContext.cs:58
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
- Migrate from RequestDispatcherWrapper (obsolete, OWIN-only) to a modern IDashboardDispatcher that works with any DashboardContext, so you are not pinned to OwinDashboardContext.
- If you must use the wrapper, ensure the dashboard is hosted under OWIN so the context is genuinely an OwinDashboardContext.
- Do not pass AspNetCoreDashboardContext or custom DashboardContext subclasses to FromDashboardContext.
Example fix
// before — Core context routed to OWIN-only factory (throws)
var ctx = RequestDispatcherContext.FromDashboardContext(aspnetCoreContext);
// after — use a modern IDashboardDispatcher that accepts DashboardContext
public Task Dispatch(DashboardContext context) { /* handle any DashboardContext */ } Defensive patterns
Strategy: type-guard
Validate before calling
if (context is not OwinDashboardContext)
throw new NotSupportedException("Use an OWIN-hosted dashboard context."); Type guard
static bool IsOwinContext(DashboardContext c) => c is OwinDashboardContext;
Try / catch
try { var ctx = RequestDispatcherContext.FromDashboardContext(context); }
catch (NotSupportedException) { /* use a modern IDashboardDispatcher instead */ } Prevention
- Do not route non-OWIN contexts (e.g. AspNetCoreDashboardContext) to the OWIN-only factory.
- Migrate to modern IDashboardDispatcher that accepts any DashboardContext.
- Keep OWIN and Core dashboard packages separate in the same app.
When it happens
Trigger: Calling RequestDispatcherContext.FromDashboardContext(context) where 'context' is a DashboardContext that is not OwinDashboardContext — e.g. an AspNetCoreDashboardContext, a test stub subclass, or a custom DashboardContext implementation. The 'as' cast at line 55 yields null and the NotSupportedException is thrown at line 58.
Common situations: Running the obsolete OWIN-based dispatcher wrapper in a non-OWIN host (ASP.NET Core) where the dashboard produces AspNetCoreDashboardContext; a test that passes a bare DashboardContext stub; mixing OWIN and Core dashboard packages in the same app and routing the wrong context type to the wrapper.
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/dd19bd4fab82c376.
Report an issue: GitHub.