HangfireIO/Hangfire · error · ArgumentNullException
name
Error message
name
What it means
Thrown by JobActivatorContext.SetJobParameter when the name parameter is null or empty. Job parameters are keyed by name in the storage layer, so an empty name has no valid storage representation.
Source
Thrown at src/Hangfire.Core/JobActivatorContext.cs:50
if (cancellationToken == null) throw new ArgumentNullException(nameof(cancellationToken));
Connection = connection;
BackgroundJob = backgroundJob;
CancellationToken = cancellationToken;
}
[NotNull]
public BackgroundJob BackgroundJob { get; }
[NotNull]
public IJobCancellationToken CancellationToken { get; }
[NotNull]
public IStorageConnection Connection { get; }
public void SetJobParameter([NotNull] string name, object value)
{
if (String.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name));
Connection.SetJobParameter(BackgroundJob.Id, name, SerializationHelper.Serialize(value, SerializationOption.User));
}
public T GetJobParameter<T>([NotNull] string name) => GetJobParameter<T>(name, allowStale: false);
public T GetJobParameter<T>([NotNull] string name, bool allowStale)
{
if (String.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name));
try
{
string value;
if (allowStale && BackgroundJob.ParametersSnapshot != null)
{
BackgroundJob.ParametersSnapshot.TryGetValue(name, out value);
}View on GitHub (pinned to c236dd0f93)
Solutions
- Validate the parameter name is non-null and non-empty before calling SetJobParameter
- Use a constant string for the parameter name to avoid dynamic null propagation
- Add a guard: if (string.IsNullOrEmpty(name)) return; or throw a more descriptive error
Example fix
// before
context.SetJobParameter(paramNameFromConfig, myValue);
// after
if (!string.IsNullOrEmpty(paramNameFromConfig))
context.SetJobParameter(paramNameFromConfig, myValue); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Parameter name must be non-empty.", nameof(name));
context.SetJobParameter(name, value); Type guard
!string.IsNullOrEmpty(name)
Prevention
- Use constant strings for parameter names to avoid null propagation
- Validate dynamically-sourced parameter names before use
- Define parameter name constants in a shared static class
When it happens
Trigger: Calling context.SetJobParameter(null, value) or context.SetJobParameter("", value) from a server filter or job method that calls SetJobParameter with a dynamically-computed name that evaluated to null/empty.
Common situations: A job parameter name derived from a configuration value or expression that is null at runtime, or a copy-paste error where the name argument was omitted.
Related errors
- WorkerCount property value should be positive.
- value
- StopTimeout must be either equal to or less than {Int32.MaxV
- ShutdownTimeout must be either equal to or less than {Int32.
- SchedulePollingInterval must be non-negative and either equa
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/ce66ee40e7252859.
Report an issue: GitHub.