HangfireIO/Hangfire · error · ArgumentNullException

activator

Error message

activator

What it means

Thrown by the SimpleJobActivatorScope constructor when the activator argument is null. This is a private nested class inside JobActivator used as the default scope; it stores the activator to resolve job instances on demand.

Source

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

        {
#pragma warning disable 618
            return BeginScope();
#pragma warning restore 618
        }

        public virtual JobActivatorScope BeginScope(PerformContext context)
        {
            return this.BeginScope(new JobActivatorContext(context.Connection, context.BackgroundJob, context.CancellationToken));
        }

        class SimpleJobActivatorScope : JobActivatorScope
        {
            private readonly JobActivator _activator;
            private readonly List<IDisposable> _disposables = new List<IDisposable>();

            public SimpleJobActivatorScope([NotNull] JobActivator activator)
            {
                if (activator == null) throw new ArgumentNullException(nameof(activator));
                _activator = activator;
            }

            public override object Resolve(Type type)
            {
                var instance = _activator.ActivateJob(type);
                var disposable = instance as IDisposable;

                if (disposable != null)
                {
                    _disposables.Add(disposable);
                }

                return instance;
            }

            public override void DisposeScope()
            {

View on GitHub (pinned to c236dd0f93)

Solutions

  1. If subclassing JobActivator and overriding BeginScope, pass a valid non-null activator (typically 'this')
  2. Avoid using reflection to construct internal types with null arguments
  3. Report as a Hangfire bug if it occurs without custom activator code

Example fix

// before (in a custom activator)
public override JobActivatorScope BeginScope(JobActivatorContext ctx)
    => new SimpleJobActivatorScope(null);

// after
public override JobActivatorScope BeginScope(JobActivatorContext ctx)
    => new SimpleJobActivatorScope(this);
Defensive patterns

Strategy: validation

Validate before calling

if (activator == null) throw new ArgumentNullException(nameof(activator));
var scope = new JobActivator.SimpleJobActivatorScope(activator); // internal - typically not called directly

Type guard

activator != null && activator is JobActivator

Prevention

When it happens

Trigger: Internally, when JobActivator.BeginScope() creates a SimpleJobActivatorScope(this) where 'this' is somehow null (which should not happen under normal conditions). This error indicates a corrupted or misuse of the activator hierarchy.

Common situations: A custom JobActivator subclass that incorrectly delegates to new SimpleJobActivatorScope(null), or reflection-based code that invokes the internal constructor with null. Extremely rare in production since the constructor is internal.

Related errors


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