HangfireIO/Hangfire · error · ArgumentNullException

command

Error message

command

What it means

AddClientBatchCommand (RouteCollectionExtensions.cs:96) throws ArgumentNullException when command is null. This overload wraps a client-side Action<IBackgroundJobClient, string> into a batch command; the command delegate is required to perform the actual client operation.

Source

Thrown at src/Hangfire.Core/Dashboard/RouteCollectionExtensions.cs:96

        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));
        }

        public static void AddClientBatchCommand(
            this RouteCollection routes,
            string pathTemplate, 
            [NotNull] Action<IBackgroundJobClient, string> command)
        {
            if (command == null) throw new ArgumentNullException(nameof(command));

            routes.AddBatchCommand(pathTemplate, (context, jobId) =>
            {
                var client = context.GetBackgroundJobClient();
                command(client, jobId);
            });
        }

        public static void AddRecurringBatchCommand(
            this RouteCollection routes,
            string pathTemplate,
            [NotNull] Action<IRecurringJobManager, string> command)
        {
            if (command == null) throw new ArgumentNullException(nameof(command));

            routes.AddBatchCommand(pathTemplate, (context, jobId) =>
            {
                var manager = context.GetRecurringJobManager();

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Provide a non-null Action<IBackgroundJobClient, string> delegate.
  2. If the command is optional, skip the registration entirely rather than passing null.

Example fix

// before
routes.AddClientBatchCommand("/requeue", null);

// after
routes.AddClientBatchCommand("/requeue", (client, jobId) => client.Requeue(jobId));
Defensive patterns

Strategy: validation

Validate before calling

if (command == null)
    throw new ArgumentNullException(nameof(command));
routes.AddClientBatchCommand("/requeue", command);

Prevention

When it happens

Trigger: Calling routes.AddClientBatchCommand(path, null) where the Action<IBackgroundJobClient,string> delegate was not supplied.

Common situations: Command delegate was conditionally assigned and the branch produced null; copy-paste omission when registering dashboard batch commands.

Related errors


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