HangfireIO/Hangfire · error · ArgumentNullException

action

Error message

action

What it means

Thrown by EmptyProfiler.InvokeMeasured (internal) when the action argument is null. The profiler is a pass-through that immediately invokes action(instance), so a null delegate would NRE on the very next line.

Source

Thrown at src/Hangfire.Core/Profiling/EmptyProfiler.cs:33

using System;

namespace Hangfire.Profiling
{
    internal sealed class EmptyProfiler : IProfiler
    {
        internal static readonly IProfiler Instance = new EmptyProfiler();

        private EmptyProfiler()
        {
        }

        public TResult InvokeMeasured<TInstance, TResult>(
            TInstance instance, 
            Func<TInstance, TResult> action,
            Func<TInstance, string> messageFunc)
        {
            if (action == null) throw new ArgumentNullException(nameof(action));
            return action(instance);
        }
    }
}

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Pass a non-null Func<TInstance, TResult> action to InvokeMeasured.
  2. Guard the call site: throw a descriptive exception if the action is null before invoking.
  3. Ensure the code constructing the measured action always supplies a real delegate.

Example fix

// before
profiler.InvokeMeasured(instance, null, msg);

// after
profiler.InvokeMeasured(instance, inst => DoMeasure(inst), msg);
Defensive patterns

Strategy: validation

Validate before calling

if (action == null) throw new ArgumentNullException(nameof(action));
return profiler.InvokeMeasured(instance, action, messageFunc);

Prevention

When it happens

Trigger: Calling EmptyProfiler.Instance.InvokeMeasured(instance, null, messageFunc) where the action delegate is null. Reached when Hangfire's profiling pipeline is handed a null measurement callback.

Common situations: A custom profiler or invocation wrapper forwards a null action; a refactor that built the action conditionally and left it null; test code exercising the profiler with a null lambda.

Related errors


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