{"record":{"id":"457feccc04abc9e7","repo":"HangfireIO/Hangfire","slug":"backgroundjob","errorCode":null,"errorMessage":"backgroundJob","messagePattern":"backgroundJob","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/JobActivatorContext.cs","lineNumber":31,"sourceCode":"// 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;\nusing Hangfire.Common;\nusing Hangfire.Storage;\n\nnamespace Hangfire\n{\n    public class JobActivatorContext\n    {\n        public JobActivatorContext(\n            [NotNull] IStorageConnection connection,\n            [NotNull] BackgroundJob backgroundJob,\n            [NotNull] IJobCancellationToken cancellationToken)\n        {\n            if (connection == null) throw new ArgumentNullException(nameof(connection));\n            if (backgroundJob == null) throw new ArgumentNullException(nameof(backgroundJob));\n            if (cancellationToken == null) throw new ArgumentNullException(nameof(cancellationToken));\n\n            Connection = connection;\n            BackgroundJob = backgroundJob;\n            CancellationToken = cancellationToken;\n        }\n\n        [NotNull]\n        public BackgroundJob BackgroundJob { get; }\n\n        [NotNull]\n        public IJobCancellationToken CancellationToken { get; }\n\n        [NotNull]\n        public IStorageConnection Connection { get; }\n\n        public void SetJobParameter([NotNull] string name, object value)\n        {","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/JobActivatorContext.cs#L13-L49","documentation":"Thrown by the JobActivatorContext constructor when the backgroundJob parameter is null. The context exposes BackgroundJob.Id for parameter operations and BackgroundJob.ParametersSnapshot for stale reads; a null value would cause downstream NullReferenceException.","triggerScenarios":"Constructing new JobActivatorContext(connection, null, cancellationToken) directly, or passing a BackgroundJob that was not properly loaded from storage.","commonSituations":"Custom server filter or test code that constructs a JobActivatorContext manually without fetching the BackgroundJob from the connection.","solutions":["Always pass a valid BackgroundJob loaded from storage or constructed with a valid Id","In tests, create a BackgroundJob with the required fields populated","Use PerformingContext.BackgroundJob rather than manually constructing the context"],"exampleFix":"// before\nvar ctx = new JobActivatorContext(conn, null, token);\n\n// after\nvar job = conn.GetBackgroundJob(jobId);\nvar ctx = new JobActivatorContext(conn, job, token);","handlingStrategy":"validation","validationCode":"var job = connection.GetBackgroundJob(jobId);\nif (job == null) throw new InvalidOperationException($\"BackgroundJob {jobId} not found in storage.\");\nvar ctx = new JobActivatorContext(connection, job, cancellationToken);","typeGuard":"backgroundJob != null && backgroundJob is BackgroundJob","tryCatchPattern":null,"preventionTips":["Load BackgroundJob from storage before constructing JobActivatorContext","In tests, create a BackgroundJob with all required fields populated","Prefer using PerformingContext.BackgroundJob rather than manual construction"],"tags":["null-argument","background-job","job-activator","hangfire"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}