{"record":{"id":"860c54832d93bf14","repo":"HangfireIO/Hangfire","slug":"connection","errorCode":null,"errorMessage":"connection","messagePattern":"connection","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/JobActivatorContext.cs","lineNumber":30,"sourceCode":"// \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;\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)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/JobActivatorContext.cs#L12-L48","documentation":"Thrown by the JobActivatorContext constructor when the connection parameter is null. JobActivatorContext wraps the storage connection for use during job performance (setting/getting parameters); a null connection makes all storage operations impossible.","triggerScenarios":"Constructing new JobActivatorContext(null, backgroundJob, cancellationToken) directly, or a code path where context.Connection is passed but the underlying IStorageConnection was not obtained.","commonSituations":"Custom filter or activator code that manually constructs a JobActivatorContext without calling storage.GetConnection(), or a test that forgets to mock the connection.","solutions":["Obtain the connection via storage.GetConnection() before constructing the context","In tests, pass a mocked IStorageConnection instance","If using PerformingContext, use context.Connection which is guaranteed non-null"],"exampleFix":"// before\nvar ctx = new JobActivatorContext(null, job, token);\n\n// after\nvar connection = storage.GetConnection();\nvar ctx = new JobActivatorContext(connection, job, token);","handlingStrategy":"validation","validationCode":"var connection = storage.GetConnection();\nif (connection == null) throw new InvalidOperationException(\"Storage returned a null connection.\");\nvar ctx = new JobActivatorContext(connection, backgroundJob, cancellationToken);","typeGuard":"connection != null && connection is IStorageConnection","tryCatchPattern":null,"preventionTips":["Always call storage.GetConnection() and verify the result before constructing JobActivatorContext","In tests, mock IStorageConnection rather than passing null","Prefer using PerformingContext.Connection which is guaranteed non-null by the framework"],"tags":["null-argument","storage-connection","job-activator","hangfire"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}