{"record":{"id":"6573a8f0b9a43abb","repo":"HangfireIO/Hangfire","slug":"profiler","errorCode":null,"errorMessage":"profiler","messagePattern":"profiler","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Profiling/ProfilerExtensions.cs","lineNumber":29,"sourceCode":"// GNU Lesser General Public License for more details.\n// \n// You should have received a copy of the GNU Lesser General Public \n// License along with Hangfire. If not, see <http://www.gnu.org/licenses/>.\n\nusing System;\nusing Hangfire.Annotations;\n\nnamespace Hangfire.Profiling\n{\n    internal static class ProfilerExtensions\n    {\n        public static void InvokeMeasured<TInstance>(\n            [NotNull] this IProfiler profiler,\n            [CanBeNull] TInstance instance, \n            [NotNull] Action<TInstance> action,\n            [CanBeNull] Func<TInstance, string> messageFunc = null)\n        {\n            if (profiler == null) throw new ArgumentNullException(nameof(profiler));\n            if (action == null) throw new ArgumentNullException(nameof(action));\n\n            profiler.InvokeMeasured(new InstanceAction<TInstance>(instance, action, messageFunc), InvokeAction, MessageCallback);\n        }\n\n        private static bool InvokeAction<TInstance>(InstanceAction<TInstance> tuple)\n        {\n            tuple.Action(tuple.Instance);\n            return true;\n        }\n\n        private static string MessageCallback<TInstance>(InstanceAction<TInstance> action)\n        {\n            return action.MessageFunc?.Invoke(action.Instance);\n        }\n\n        internal struct InstanceAction<TInstance>\n        {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Profiling/ProfilerExtensions.cs#L11-L47","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\nIProfiler profiler = null;\nprofiler.InvokeMeasured(instance, action);\n\n// after\nIProfiler profiler = new SlowLogProfiler(LogProvider.GetCurrentClassLogger());\nprofiler.InvokeMeasured(instance, action);","handlingStrategy":"validation","validationCode":"if (profiler == null) throw new InvalidOperationException(\"Profiler must be configured before invoking measured operations.\");\nprofiler.InvokeMeasured(instance, action);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["profiling","argument-null","internal"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}