HangfireIO/Hangfire · error · ArgumentNullException
routes
Error message
routes
What it means
The OWIN-specific AddBatchCommand overload (RouteCollectionExtensions.cs:71) throws ArgumentNullException when the routes parameter (the RouteCollection being extended) is null. The extension method cannot register a command dispatcher without a target collection.
Source
Thrown at src/Hangfire.Core/Dashboard/RouteCollectionExtensions.cs:71
[NotNull] this RouteCollection routes,
[NotNull] string pathTemplate,
[NotNull] Func<DashboardContext, bool> command)
{
if (routes == null) throw new ArgumentNullException(nameof(routes));
if (pathTemplate == null) throw new ArgumentNullException(nameof(pathTemplate));
if (command == null) throw new ArgumentNullException(nameof(command));
routes.Add(pathTemplate, new CommandDispatcher(command));
}
#if FEATURE_OWIN
[Obsolete("Use the AddBatchCommand(RouteCollection, string, Func<DashboardContext, bool>) overload instead. Will be removed in 2.0.0.")]
public static void AddBatchCommand(
[NotNull] this RouteCollection routes,
[NotNull] string pathTemplate,
[NotNull] Action<RequestDispatcherContext, string> command)
{
if (routes == null) throw new ArgumentNullException(nameof(routes));
if (pathTemplate == null) throw new ArgumentNullException(nameof(pathTemplate));
if (command == null) throw new ArgumentNullException(nameof(command));
routes.Add(pathTemplate, new BatchCommandDispatcher(command));
}
#endif
public static void AddBatchCommand(
[NotNull] this RouteCollection routes,
[NotNull] string pathTemplate,
[NotNull] Action<DashboardContext, string> command)
{
if (routes == null) throw new ArgumentNullException(nameof(routes));
if (pathTemplate == null) throw new ArgumentNullException(nameof(pathTemplate));
if (command == null) throw new ArgumentNullException(nameof(command));
routes.Add(pathTemplate, new BatchCommandDispatcher(command));
}View on GitHub (pinned to c236dd0f93)
Solutions
- Ensure the RouteCollection instance passed as 'routes' is non-null and properly initialized before calling AddBatchCommand.
- Pass the dashboard's Routes collection directly rather than a cached/nullable reference.
Example fix
// before
RouteCollection routes = null;
routes.AddBatchCommand("/delete", (ctx, id) => true);
// after
var routes = new RouteCollection();
routes.AddBatchCommand("/delete", (ctx, id) => true); Defensive patterns
Strategy: validation
Validate before calling
if (routes == null)
throw new ArgumentNullException(nameof(routes));
routes.AddBatchCommand("/cmd", (ctx, id) => true); Prevention
- Initialize the RouteCollection before calling any Add* extension methods.
- Use the dashboard pipeline's built-in Routes collection.
When it happens
Trigger: Calling routes.AddBatchCommand(...) (the OWIN Action<RequestDispatcherContext,string> overload) where the routes variable is null.
Common situations: Dashboard routes collection was not initialized or was set to null before the extension method call; custom dashboard setup code with a null guard missing.
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/cd7222e25c3bfb20.
Report an issue: GitHub.