{"record":{"id":"e98469fd774f95fd","repo":"HangfireIO/Hangfire","slug":"jobactivator-returned-null-instance-of-the-type","errorCode":null,"errorMessage":"JobActivator returned NULL instance of the '{Type}' type.","messagePattern":"JobActivator returned NULL instance of the '(.+?)' type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Obsolete/Job.Obsolete.cs","lineNumber":84,"sourceCode":"            }\n            finally\n            {\n                Dispose(instance);\n            }\n\n            return result;\n        }\n\n        [Obsolete(\"Will be removed in 2.0.0\")]\n        private object Activate(JobActivator activator)\n        {\n            try\n            {\n                var instance = activator.ActivateJob(Type);\n\n                if (instance == null)\n                {\n                    throw new InvalidOperationException($\"JobActivator returned NULL instance of the '{Type}' type.\");\n                }\n\n                return instance;\n            }\n            catch (Exception ex) when (ex.IsCatchableExceptionType())\n            {\n                throw new JobPerformanceException(\n                    \"An exception occurred during job activation.\",\n                    ex);\n            }\n        }\n\n        [Obsolete(\"Will be removed in 2.0.0\")]\n        private object[] GetArguments(IJobCancellationToken cancellationToken)\n        {\n            try\n            {\n                var parameters = Method.GetParameters();","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Obsolete/Job.Obsolete.cs#L66-L102","documentation":"Thrown as InvalidOperationException (wrapped in JobPerformanceException) when a JobActivator.ActivateJob returns null for the job's Type. Hangfire requires a non-null instance to invoke the method; a null return usually signals a misconfigured DI scope (e.g. a service not registered, a scoped service resolved outside its scope, or a manual activator returning null). The obsolete Activate() private method checks the result at line 84.","triggerScenarios":"Job.Perform (obsolete) invokes Activate(activator) -> activator.ActivateJob(Type) which returns null. Common with a custom JobActivator whose Resolve/ActivateJob returns null, or a DI-based activator (AspNetCoreJobActivator, Autofac) that cannot resolve the job type because it isn't registered in the container.","commonSituations":"The job class is not registered in the DI container (especially with scoped/lifetime resolution in ASP.NET Core); a constructor on the job type throws silently or the DI provider returns null for an unregistered service; using a third-party activator that returns null for open generics or interface-based jobs; a stale job in storage referencing a type that was since removed from the assembly.","solutions":["Register the job type in your DI container so the activator can resolve it (e.g. services.AddTransient<MyJob>()).","Verify the job class has a public parameterless constructor if using the default JobActivator (Activator.CreateInstance), or register it for DI.","If using a custom JobActivator, make ActivateJob throw a descriptive exception instead of returning null.","Ensure the job type still exists in the deployed assembly — stale jobs referencing removed types should be deleted from storage."],"exampleFix":"// before — MyJob not registered, DI activator returns null\n// job fails: JobActivator returned NULL instance of the 'MyJob' type.\n\n// after\nservices.AddTransient<MyJob>();\nservices.AddHangfire((sp, cfg) => cfg.UseActivator(new AspNetCoreJobActivator(sp)));","handlingStrategy":"try-catch","validationCode":"// Before perform, verify the type is resolvable by your activator:\n// (DI containers expose IsRegistered / TryResolve)\nif (!serviceProvider.GetService(typeof(MyJob)).TryGetTarget(out _))\n    throw new InvalidOperationException(\"Job type not registered.\");","typeGuard":null,"tryCatchPattern":"try { job.Perform(activator, token); }\ncatch (JobPerformanceException ex) when (ex.InnerException is InvalidOperationException ioe\n    && ioe.Message.Contains(\"returned NULL\"))\n{\n    logger.LogError(ex, \"Job type could not be activated — register it in DI.\");\n}","preventionTips":["Register every job type in your DI container.","Implement a custom JobActivator that throws a descriptive error instead of returning null.","Use AspNetCoreJobActivator (or equivalent) scoped correctly to resolve job types."],"tags":["job-performance","di","job-activator","obsolete","activation"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}