HangfireIO/Hangfire · error · ArgumentNullException

value

Error message

value

What it means

This exception (ArgumentNullException("value") or ArgumentException("You should specify at least one queue to listen.") in the same setter) is thrown by the Queues setter of BackgroundJobServerOptions when the supplied string[] is null (ArgumentNullException) or empty (ArgumentException). The server must subscribe to at least one queue to fetch jobs from; the default is { EnqueuedState.DefaultQueue } ("default").

Source

Thrown at src/Hangfire.Core/BackgroundJobServerOptions.cs:83

        public bool IsLightweightServer { get; set; }

        public int WorkerCount
        {
            get { return _workerCount; }
            set
            {
                if (value <= 0) throw new ArgumentOutOfRangeException(nameof(value), "WorkerCount property value should be positive.");

                _workerCount = value;
            }
        }

        public string[] Queues
        {
            get { return _queues; }
            set
            {
                if (value == null) throw new ArgumentNullException(nameof(value));
                if (value.Length == 0) throw new ArgumentException("You should specify at least one queue to listen.", nameof(value));

                _queues = value;
            }
        }

        public TimeSpan StopTimeout
        {
            get => _stopTimeout;
            set
            {
                if ((value < TimeSpan.Zero && value != Timeout.InfiniteTimeSpan) || value.TotalMilliseconds > Int32.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(nameof(value), $"StopTimeout must be either equal to or less than {Int32.MaxValue} milliseconds and non-negative or infinite");
                }
                _stopTimeout = value;
            }
        }

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Provide at least one queue name, e.g. options.Queues = new[] { "default", "critical" }.
  2. Coerce config: if the parsed list is null/empty, fall back to new[] { EnqueuedState.DefaultQueue }.
  3. Do not assign Queues at all to keep the default ("default").
  4. Validate the queue list at startup before constructing the server.

Example fix

// before
options.Queues = config.GetSection("Queues").Get<string[]>(); // null when missing

// after
var queues = config.GetSection("Queues").Get<string[]>();
options.Queues = queues is { Length: > 0 } ? queues : new[] { EnqueuedState.DefaultQueue };
Defensive patterns

Strategy: validation

Validate before calling

var queues = config.GetSection("Queues").Get<string[]>();
options.Queues = queues is { Length: > 0 } ? queues : new[] { EnqueuedState.DefaultQueue };

Type guard

static bool AreQueuesValid(string[] queues) => queues is { Length: > 0 };

Try / catch

try { options.Queues = queues; }
catch (ArgumentException) { options.Queues = new[] { EnqueuedState.DefaultQueue }; }

Prevention

When it happens

Trigger: Assigning options.Queues = null; assigning options.Queues = Array.Empty<string>() or new string[0]; binding from a config section that produced no entries.

Common situations: Configuration binding for Queues returns an empty array when the section is absent; a code path that conditionally sets Queues only when a feature flag is on, leaving it null; tests that initialize Queues to an empty list; refactor that removed the default queue.

Related errors


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