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

  1. Validate the parameter name is non-null and non-empty before calling SetJobParameter
  2. Use a constant string for the parameter name to avoid dynamic null propagation
  3. 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

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


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