HangfireIO/Hangfire · error · JobPerformanceException

An exception occurred during job activation.

Error message

An exception occurred during job activation.

What it means

Thrown as JobPerformanceException (message 'An exception occurred during job activation.') wrapping any catchable exception raised while the JobActivator tried to instantiate the job type. The obsolete Activate() method at lines 78-94 catches the inner exception and rethrows it inside a JobPerformanceException so the worker pipeline treats activation failures uniformly with other performance errors.

Source

Thrown at src/Hangfire.Core/Obsolete/Job.Obsolete.cs:91

        }

        [Obsolete("Will be removed in 2.0.0")]
        private object Activate(JobActivator activator)
        {
            try
            {
                var instance = activator.ActivateJob(Type);

                if (instance == null)
                {
                    throw new InvalidOperationException($"JobActivator returned NULL instance of the '{Type}' type.");
                }

                return instance;
            }
            catch (Exception ex) when (ex.IsCatchableExceptionType())
            {
                throw new JobPerformanceException(
                    "An exception occurred during job activation.",
                    ex);
            }
        }

        [Obsolete("Will be removed in 2.0.0")]
        private object[] GetArguments(IJobCancellationToken cancellationToken)
        {
            try
            {
                var parameters = Method.GetParameters();
                var result = new List<object>(Args.Count);

                for (var i = 0; i < parameters.Length; i++)
                {
                    var parameter = parameters[i];
                    var argument = Args[i];

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Inspect the InnerException of the JobPerformanceException to find the real activation error and address it (register the service, fix the constructor, add the dependency).
  2. Ensure the job type has a resolvable constructor — either public parameterless for the default activator, or registered with the DI container for a DI activator.
  3. If the constructor performs work that can fail, move that work into the job method body so activation stays cheap and reliable.

Example fix

// before — constructor throws, activation fails
public MyJob() { _conn = new SqlConnection(_cs); _conn.Open(); }

// after — move failure-prone work into the method
public MyJob() { }
public void Run() { using var c = new SqlConnection(_cs); c.Open(); ... }
Defensive patterns

Strategy: try-catch

Validate before calling

// No pre-check reliably predicts constructor failure; ensure the type is
// registered and has a resolvable ctor before performing.
services.AddTransient<MyJob>();

Try / catch

try { job.Perform(activator, token); }
catch (JobPerformanceException ex) when (ex.Message.Contains("during job activation"))
{
    logger.LogError(ex.InnerException, "Activation failed for {Job}", job.Type);
}

Prevention

When it happens

Trigger: Job.Perform (obsolete) calls Activate(activator); activator.ActivateJob(Type) throws — e.g. MissingMethodException (no matching constructor), a constructor that throws, a DI resolution exception, or a type-load failure. The catch filter (ex.IsCatchableExceptionType) wraps it into JobPerformanceException.

Common situations: The job type lacks a public parameterless constructor and no DI activator is configured; the job's constructor throws (e.g. reads config that is missing, opens a connection that fails); the type fails to load due to a missing dependency assembly; a scoped DI service is resolved outside its lifetime scope.

Related errors


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