HangfireIO/Hangfire · error · ArgumentNullException
pathTemplate
Error message
pathTemplate
What it means
The OWIN-specific AddBatchCommand overload (RouteCollectionExtensions.cs:72) throws ArgumentNullException when pathTemplate is null. The route collection needs a non-null path string to map the command dispatcher to a URL.
Source
Thrown at src/Hangfire.Core/Dashboard/RouteCollectionExtensions.cs:72
[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
- Provide a non-null path string (e.g. "/enqueue").
- Validate configuration values before passing them as pathTemplate.
Example fix
// before routes.AddBatchCommand(config.DeletePath, (ctx, id) => Delete(id)); // config.DeletePath is null // after routes.AddBatchCommand(config.DeletePath ?? "/delete", (ctx, id) => Delete(id));
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(pathTemplate))
throw new ArgumentException("pathTemplate is required.");
routes.AddBatchCommand(pathTemplate, handler); Prevention
- Use non-null path string constants for route registration.
- Validate config-sourced paths before use.
When it happens
Trigger: Calling routes.AddBatchCommand(null, command) or routes.AddBatchCommand(someVariableThatIsNull, command) on the OWIN overload.
Common situations: Path template sourced from configuration that resolved to null; typo or missing constant; conditional path that evaluated to null.
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/1c50cd993bc369bb.
Report an issue: GitHub.