HangfireIO/Hangfire · error · ArgumentNullException

routes

Error message

routes

What it means

Thrown as ArgumentNullException by the DashboardMiddleware constructor when the 'routes' RouteCollection argument is null. DashboardMiddleware is an internal OWIN middleware that wires the configured RouteCollection into the per-request dispatcher lookup; a null routes collection makes it impossible to resolve dashboard URLs, so the constructor fails fast.

Source

Thrown at src/Hangfire.Core/Obsolete/DashboardMiddleware.cs:46

    internal sealed class DashboardMiddleware : OwinMiddleware
    {
        private readonly string _appPath;
        private readonly int _statsPollingInterval;
        private readonly JobStorage _storage;
        private readonly RouteCollection _routes;
        private readonly IEnumerable<IAuthorizationFilter> _authorizationFilters;

        public DashboardMiddleware(
            OwinMiddleware next,
            string appPath,
            int statsPollingInterval,
            [NotNull] JobStorage storage,
            [NotNull] RouteCollection routes, 
            [NotNull] IEnumerable<IAuthorizationFilter> authorizationFilters)
            : base(next)
        {
            if (storage == null) throw new ArgumentNullException(nameof(storage));
            if (routes == null) throw new ArgumentNullException(nameof(routes));
            if (authorizationFilters == null) throw new ArgumentNullException(nameof(authorizationFilters));

            _appPath = appPath;
            _statsPollingInterval = statsPollingInterval;
            _storage = storage;
            _routes = routes;
            _authorizationFilters = authorizationFilters;
        }

        public override Task Invoke(IOwinContext owinContext)
        {
            var dispatcher = _routes.FindDispatcher(owinContext.Request.Path.Value);
            
            if (dispatcher == null)
            {
                return Next.Invoke(owinContext);
            }

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Ensure the RouteCollection passed as the routes argument is non-null — normally DashboardRoutes.Routes from the Hangfire dashboard configuration.
  2. Prefer the higher-level IAppBuilder.UseHangfireDashboard extension instead of registering DashboardMiddleware directly, so routes are wired for you.
  3. If you maintain a custom route collection, verify it is constructed and assigned before the OWIN middleware is added to the pipeline.

Example fix

// before
app.Use<DashboardMiddleware>(appPath, storage, null, authFilters);

// after
app.Use<DashboardMiddleware>(appPath, storage, DashboardRoutes.Routes, authFilters);
Defensive patterns

Strategy: validation

Validate before calling

if (routes == null) throw new ArgumentNullException(nameof(routes));
app.Use<DashboardMiddleware>(appPath, storage, routes ?? DashboardRoutes.Routes, authFilters);

Prevention

When it happens

Trigger: Instantiating DashboardMiddleware (directly or via the OWIN 'app.Use<DashboardMiddleware>(...)' pipeline) without supplying a non-null RouteCollection for the routes parameter. The OWIN activation layer injects constructor arguments positionally, so passing null or omitting the routes argument triggers line 46.

Common situations: Custom OWIN pipeline wiring that tries to register a dashboard middleware manually without forwarding DashboardRoutes.Routes; a refactor or version upgrade where the RouteCollection field was replaced by null; tests that mock the OWIN middleware graph with stub objects.

Related errors


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