{"record":{"id":"b5c20755009b7ce6","repo":"HangfireIO/Hangfire","slug":"value-b5c207","errorCode":null,"errorMessage":"value","messagePattern":"value","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/JobActivator.cs","lineNumber":38,"sourceCode":"\nnamespace Hangfire\n{\n    public class JobActivator\n    {\n        private static JobActivator _current = new JobActivator();\n\n        /// <summary>\n        /// Gets or sets the current <see cref=\"JobActivator\"/> instance \n        /// that will be used to activate jobs during performance.\n        /// </summary>\n        public static JobActivator Current\n        {\n            get { return _current; }\n            set\n            {\n                if (value == null)\n                {\n                    throw new ArgumentNullException(nameof(value));\n                }\n\n                _current = value;\n            }\n        }\n\n        \n        public virtual object ActivateJob(Type jobType)\n        {\n            return Activator.CreateInstance(jobType);\n        }\n\n        [Obsolete(\"Please implement/use the BeginScope(JobActivatorContext) method instead. Will be removed in 2.0.0.\")]\n        public virtual JobActivatorScope BeginScope()\n        {\n            return new SimpleJobActivatorScope(this);\n        }\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/JobActivator.cs#L20-L56","documentation":"Thrown by the setter of JobActivator.Current when an attempt is made to set it to null. JobActivator.Current is the global activator used to instantiate job classes; a null value would cause NullReferenceException at job execution time, so Hangfire rejects it upfront.","triggerScenarios":"Executing JobActivator.Current = null; or assigning a variable that evaluated to null (e.g., a DI container returning null for the activator).","commonSituations":"Resetting the activator during test teardown without restoring a default, or a custom activator factory method returning null under certain conditions.","solutions":["Assign a valid JobActivator instance, or the default new JobActivator()","If using a DI-based activator (e.g., AspNetCoreJobActivator), ensure the DI scope produces a non-null instance","In test cleanup, restore JobActivator.Current = new JobActivator() rather than setting null"],"exampleFix":"// before\nJobActivator.Current = null;\n\n// after\nJobActivator.Current = new MyCustomActivator();\n// or restore default\nJobActivator.Current = new JobActivator();","handlingStrategy":"validation","validationCode":"if (myActivator == null)\n    throw new InvalidOperationException(\"Cannot set JobActivator.Current to a null instance.\");\nJobActivator.Current = myActivator;","typeGuard":"value != null && value is JobActivator","tryCatchPattern":null,"preventionTips":["Never assign null to JobActivator.Current; use new JobActivator() for the default","In DI scenarios, ensure the activator is resolved before assignment","Add null checks in test teardown to restore a default activator"],"tags":["job-activator","null-argument","static-state","hangfire"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}