{"record":{"id":"dd19bd4fab82c376","repo":"HangfireIO/Hangfire","slug":"context-must-be-of-type-owindashboardcontext","errorCode":null,"errorMessage":"context must be of type 'OwinDashboardContext'","messagePattern":"context must be of type 'OwinDashboardContext'","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Obsolete/RequestDispatcherContext.cs","lineNumber":58,"sourceCode":"            JobStorage = jobStorage;\n            OwinEnvironment = owinEnvironment;\n            UriMatch = uriMatch;\n        }\n\n        public string AppPath { get; }\n        public int StatsPollingInterval { get; }\n        public JobStorage JobStorage { get; }\n        public IDictionary<string, object> OwinEnvironment { get; } \n        public Match UriMatch { get; }\n\n        public static RequestDispatcherContext FromDashboardContext([NotNull] DashboardContext context)\n        {\n            if (context == null) throw new ArgumentNullException(nameof(context));\n\n            var owinContext = context as OwinDashboardContext;\n            if (owinContext == null)\n            {\n                throw new NotSupportedException($\"context must be of type '{nameof(OwinDashboardContext)}'\");\n            }\n            \n            return new RequestDispatcherContext(\n                owinContext.Options.AppPath,\n                owinContext.Options.StatsPollingInterval,\n                owinContext.Storage,\n                owinContext.Environment,\n                owinContext.UriMatch);\n        }\n    }\n}","sourceCodeStart":40,"sourceCodeEnd":69,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Obsolete/RequestDispatcherContext.cs#L40-L69","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — Core context routed to OWIN-only factory (throws)\nvar ctx = RequestDispatcherContext.FromDashboardContext(aspnetCoreContext);\n\n// after — use a modern IDashboardDispatcher that accepts DashboardContext\npublic Task Dispatch(DashboardContext context) { /* handle any DashboardContext */ }","handlingStrategy":"type-guard","validationCode":"if (context is not OwinDashboardContext)\n    throw new NotSupportedException(\"Use an OWIN-hosted dashboard context.\");","typeGuard":"static bool IsOwinContext(DashboardContext c) => c is OwinDashboardContext;","tryCatchPattern":"try { var ctx = RequestDispatcherContext.FromDashboardContext(context); }\ncatch (NotSupportedException) { /* use a modern IDashboardDispatcher instead */ }","preventionTips":["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."],"tags":["not-supported","dashboard","owin","host-mismatch","obsolete"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}