HangfireIO/Hangfire · error · ArgumentNullException

value

Error message

value

What it means

Thrown by the setter of JobActivator.Current when an attempt is made to set it to null. JobActivator.Current is the global activator used to instantiate job classes; a null value would cause NullReferenceException at job execution time, so Hangfire rejects it upfront.

Source

Thrown at src/Hangfire.Core/JobActivator.cs:38

namespace Hangfire
{
    public class JobActivator
    {
        private static JobActivator _current = new JobActivator();

        /// <summary>
        /// Gets or sets the current <see cref="JobActivator"/> instance 
        /// that will be used to activate jobs during performance.
        /// </summary>
        public static JobActivator Current
        {
            get { return _current; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException(nameof(value));
                }

                _current = value;
            }
        }

        
        public virtual object ActivateJob(Type jobType)
        {
            return Activator.CreateInstance(jobType);
        }

        [Obsolete("Please implement/use the BeginScope(JobActivatorContext) method instead. Will be removed in 2.0.0.")]
        public virtual JobActivatorScope BeginScope()
        {
            return new SimpleJobActivatorScope(this);
        }

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Assign a valid JobActivator instance, or the default new JobActivator()
  2. If using a DI-based activator (e.g., AspNetCoreJobActivator), ensure the DI scope produces a non-null instance
  3. In test cleanup, restore JobActivator.Current = new JobActivator() rather than setting null

Example fix

// before
JobActivator.Current = null;

// after
JobActivator.Current = new MyCustomActivator();
// or restore default
JobActivator.Current = new JobActivator();
Defensive patterns

Strategy: validation

Validate before calling

if (myActivator == null)
    throw new InvalidOperationException("Cannot set JobActivator.Current to a null instance.");
JobActivator.Current = myActivator;

Type guard

value != null && value is JobActivator

Prevention

When it happens

Trigger: Executing JobActivator.Current = null; or assigning a variable that evaluated to null (e.g., a DI container returning null for the activator).

Common situations: Resetting the activator during test teardown without restoring a default, or a custom activator factory method returning null under certain conditions.

Related errors


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