HangfireIO/Hangfire · error · ArgumentNullException

dispatcher

Error message

dispatcher

What it means

Thrown as ArgumentNullException by the obsolete RequestDispatcherWrapper constructor when the 'dispatcher' IRequestDispatcher argument is null. The wrapper adapts a legacy IRequestDispatcher to the modern IDashboardDispatcher interface by delegating Dispatch; a null inner dispatcher has nothing to delegate to, so the constructor rejects it at line 30.

Source

Thrown at src/Hangfire.Core/Obsolete/RequestDispatcherWrapper.cs:30

// 
// You should have received a copy of the GNU Lesser General Public 
// License along with Hangfire. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Threading.Tasks;
using Hangfire.Annotations;

// ReSharper disable once CheckNamespace
namespace Hangfire.Dashboard
{
    [Obsolete("Use IDashboardDispatcher-based dispatchers instead. Will be removed in 2.0.0.")]
    public class RequestDispatcherWrapper : IDashboardDispatcher
    {
        private readonly IRequestDispatcher _dispatcher;
        
        public RequestDispatcherWrapper([NotNull] IRequestDispatcher dispatcher)
        {
            if (dispatcher == null) throw new ArgumentNullException(nameof(dispatcher));
            _dispatcher = dispatcher;
        }

        public Task Dispatch(DashboardContext context)
        {
            return _dispatcher.Dispatch(RequestDispatcherContext.FromDashboardContext(context));
        }
    }
}

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Migrate your dispatcher to implement IDashboardDispatcher directly and register it without the obsolete wrapper.
  2. If you must use the wrapper, ensure the IRequestDispatcher instance is constructed and non-null before wrapping (guard the factory result).
  3. Register routes with a non-null dispatcher: routes.Add(path, new RequestDispatcherWrapper(myDispatcher)).

Example fix

// before
routes.Add("/jobs", new RequestDispatcherWrapper(null));

// after
routes.Add("/jobs", new MyModernDispatcher()); // implements IDashboardDispatcher
Defensive patterns

Strategy: validation

Validate before calling

if (dispatcher == null) throw new ArgumentNullException(nameof(dispatcher));
routes.Add("/path", new RequestDispatcherWrapper(dispatcher));

Prevention

When it happens

Trigger: Constructing 'new RequestDispatcherWrapper(null)' — i.e. wrapping a null IRequestDispatcher, typically because the dispatcher instance was never created, failed to resolve from a factory, or was lost in a refactor.

Common situations: Custom dashboard route registration that wraps legacy dispatchers but passes null due to a factory returning null; migration from IRequestDispatcher to IDashboardDispatcher where the adapter is constructed before the adaptee exists; tests that stub the wrapper without a real dispatcher.

Related errors


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