{"record":{"id":"0c7843e21a266175","repo":"HangfireIO/Hangfire","slug":"execution","errorCode":null,"errorMessage":"execution","messagePattern":"execution","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Processing/BackgroundDispatcher.cs","lineNumber":47,"sourceCode":"{\n    internal sealed class BackgroundDispatcher : IBackgroundDispatcher\n    {\n        private readonly ILog _logger = LogProvider.GetLogger(typeof(BackgroundDispatcher));\n        private readonly CountdownEvent _stopped;\n\n        private readonly IBackgroundExecution _execution;\n        private readonly Action<Guid, object> _action;\n        private readonly object _state;\n\n        public BackgroundDispatcher(\n            [NotNull] IBackgroundExecution execution,\n            [NotNull] Action<Guid, object> action,\n            [CanBeNull] object state,\n            [NotNull] Func<ThreadStart, IEnumerable<Thread>> threadFactory)\n        {\n            if (threadFactory == null) throw new ArgumentNullException(nameof(threadFactory));\n\n            _execution = execution ?? throw new ArgumentNullException(nameof(execution));\n            _action = action ?? throw new ArgumentNullException(nameof(action));\n            _state = state;\n\n#if !NETSTANDARD1_3\n            AppDomainUnloadMonitor.EnsureInitialized();\n#endif\n\n            var threads = threadFactory(DispatchLoop)?.ToArray();\n\n            if (threads == null || threads.Length == 0)\n            {\n                throw new ArgumentException(\"At least one unstarted thread should be created.\", nameof(threadFactory));\n            }\n\n            if (threads.Any(static thread => thread == null || (thread.ThreadState & ThreadState.Unstarted) == 0))\n            {\n                throw new ArgumentException(\"All the threads should be non-null and in the ThreadState.Unstarted state.\", nameof(threadFactory));\n            }","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Processing/BackgroundDispatcher.cs#L29-L65","documentation":"Thrown as ArgumentNullException by the BackgroundDispatcher constructor when the 'execution' IBackgroundExecution argument is null. The execution object owns the work queue and scheduling that the dispatcher's threads consume; a null execution leaves the dispatch loop with nothing to run, so the constructor rejects it via '?? throw' at line 47.","triggerScenarios":"Constructing a BackgroundDispatcher with a null IBackgroundExecution. BackgroundDispatcher is internal and is normally built by the processing server with a configured execution; a null execution only arises from custom processing-server code or tests that build the dispatcher manually.","commonSituations":"A custom processing server that instantiates BackgroundDispatcher without an IBackgroundExecution; a test stub that omits the execution; a refactor where the execution was replaced by null. Standard BackgroundJobServer users never pass this argument.","solutions":["If you maintain a custom processing server, ensure a non-null IBackgroundExecution is created and passed (the framework normally builds one for the configured worker count).","Use the public BackgroundJobServer API, which constructs the execution and dispatcher internally.","In tests, provide a real or mock IBackgroundExecution rather than null."],"exampleFix":"// before\nvar d = new BackgroundDispatcher(null, action, state, factory);\n\n// after\nvar execution = new BackgroundExecution(serverOptions, state);\nvar d = new BackgroundDispatcher(execution, action, state, factory);","handlingStrategy":"validation","validationCode":"if (execution == null) throw new ArgumentNullException(nameof(execution));\nvar execution = new BackgroundExecution(serverOptions, state);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the public BackgroundJobServer API which constructs the execution internally.","In custom servers/tests, provide a real or mock IBackgroundExecution, never null."],"tags":["argument-null","processing","execution","internal-api"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}