{"record":{"id":"e253e8f15858e216","repo":"HangfireIO/Hangfire","slug":"execution-e253e8","errorCode":null,"errorMessage":"execution","messagePattern":"execution","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Processing/BackgroundDispatcherAsync.cs","lineNumber":49,"sourceCode":"\n        private readonly IBackgroundExecution _execution;\n        private readonly Func<Guid, object, Task> _action;\n        private readonly object _state;\n\n        private readonly TaskScheduler _taskScheduler;\n        private readonly bool _ownsScheduler;\n\n        public BackgroundDispatcherAsync(\n            [NotNull] IBackgroundExecution execution,\n            [NotNull] Func<Guid, object, Task> action,\n            [CanBeNull] object state,\n            [NotNull] TaskScheduler taskScheduler,\n            int maxConcurrency,\n            bool ownsScheduler)\n        {\n            if (maxConcurrency <= 0) throw new ArgumentOutOfRangeException(nameof(maxConcurrency));\n\n            _execution = execution ?? throw new ArgumentNullException(nameof(execution));\n            _action = action ?? throw new ArgumentNullException(nameof(action));\n            _state = state;\n            _taskScheduler = taskScheduler ?? throw new ArgumentNullException(nameof(taskScheduler));\n            _ownsScheduler = ownsScheduler;\n\n#if !NETSTANDARD1_3\n            AppDomainUnloadMonitor.EnsureInitialized();\n#endif\n\n            _stopped = new CountdownEvent(maxConcurrency);\n\n            for (var i = 0; i < maxConcurrency; i++)\n            {\n                Task.Factory.StartNew(\n                    DispatchLoop,\n                    CancellationToken.None,\n                    TaskCreationOptions.None,\n                    _taskScheduler).Unwrap();","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Processing/BackgroundDispatcherAsync.cs#L31-L67","documentation":"Thrown by BackgroundDispatcherAsync's constructor (internal) when the IBackgroundExecution argument is null. The dispatcher delegates all work (RunAsync) to that execution, so a null instance has nothing to drive.","triggerScenarios":"Constructing BackgroundDispatcherAsync with execution == null. Internal wiring that failed to create/resolve the BackgroundExecution dependency before building the dispatcher.","commonSituations":"DI/registration defect where the execution instance was not created; a null propagated from a factory method that returned null on a missing storage dependency; unit test stubbing that forgot to supply the execution.","solutions":["Ensure a non-null IBackgroundExecution (BackgroundExecution instance) is created and passed.","Guard the call site with a null check and fail fast with a clearer message before reaching the constructor.","Verify the dependency-injection registration that supplies the execution is active and not returning null."],"exampleFix":"// before\nvar dispatcher = new BackgroundDispatcherAsync(null, action, state, scheduler, 4, false);\n\n// after\nvar execution = execution ?? throw new InvalidOperationException(\"Execution must be initialized before the dispatcher.\");\nvar dispatcher = new BackgroundDispatcherAsync(execution, action, state, scheduler, 4, false);","handlingStrategy":"validation","validationCode":"if (execution == null) throw new InvalidOperationException(\"IBackgroundExecution must be created before the dispatcher.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct the BackgroundExecution before the dispatcher that consumes it.","Verify DI registrations resolve the execution service.","Fail fast at startup with a clear message rather than letting null propagate."],"tags":["hangfire","null-argument","argument-validation","background-processing"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}