HangfireIO/Hangfire · error · ArgumentNullException
profiler
Error message
profiler
What it means
Thrown by the internal InvokeMeasured extension method on IProfiler when the profiler argument itself is null. This is a defensive precondition guard inside Hangfire's profiling infrastructure that wraps measured invocations. It signals a programming error inside the library or a custom IProfiler integration where a null profiler was passed rather than a real instance.
Source
Thrown at src/Hangfire.Core/Profiling/ProfilerExtensions.cs:29
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with Hangfire. If not, see <http://www.gnu.org/licenses/>.
using System;
using Hangfire.Annotations;
namespace Hangfire.Profiling
{
internal static class ProfilerExtensions
{
public static void InvokeMeasured<TInstance>(
[NotNull] this IProfiler profiler,
[CanBeNull] TInstance instance,
[NotNull] Action<TInstance> action,
[CanBeNull] Func<TInstance, string> messageFunc = null)
{
if (profiler == null) throw new ArgumentNullException(nameof(profiler));
if (action == null) throw new ArgumentNullException(nameof(action));
profiler.InvokeMeasured(new InstanceAction<TInstance>(instance, action, messageFunc), InvokeAction, MessageCallback);
}
private static bool InvokeAction<TInstance>(InstanceAction<TInstance> tuple)
{
tuple.Action(tuple.Instance);
return true;
}
private static string MessageCallback<TInstance>(InstanceAction<TInstance> action)
{
return action.MessageFunc?.Invoke(action.Instance);
}
internal struct InstanceAction<TInstance>
{View on GitHub (pinned to c236dd0f93)
Solutions
- Ensure the IProfiler instance is non-null before calling InvokeMeasured — inject SlowLogProfiler or a custom profiler via DI.
- If writing a custom IProfiler consumer, resolve the profiler from the same composition root as other Hangfire services rather than constructing it manually as null.
- In tests, provide a real or mock IProfiler (e.g. new SlowLogProfiler(logger)) instead of null.
Example fix
// before IProfiler profiler = null; profiler.InvokeMeasured(instance, action); // after IProfiler profiler = new SlowLogProfiler(LogProvider.GetCurrentClassLogger()); profiler.InvokeMeasured(instance, action);
Defensive patterns
Strategy: validation
Validate before calling
if (profiler == null) throw new InvalidOperationException("Profiler must be configured before invoking measured operations.");
profiler.InvokeMeasured(instance, action); Prevention
- Register IProfiler through the Hangfire composition root so it is never null.
- In tests, always construct a SlowLogProfiler with a logger instead of passing null.
- Treat a null IProfiler as a fatal wiring error and fail fast at startup.
When it happens
Trigger: Calling profiler.InvokeMeasured(instance, action) where the 'profiler' variable (the 'this' target of the extension method) is null. This happens when a custom component injects or resolves a null IProfiler, or when a test/helper constructs a code path that bypasses profiler initialization.
Common situations: Writing a custom server process or filter that accepts an IProfiler dependency but receives null from a DI container misconfiguration. Unit testing internal Hangfire components without providing a profiler instance (e.g. null substituted for IProfiler).
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/6573a8f0b9a43abb.
Report an issue: GitHub.