{"record":{"id":"25b197cbb203ec8d","repo":"HangfireIO/Hangfire","slug":"jobactivator-returned-null-instance-of-the-conte","errorCode":null,"errorMessage":"JobActivator returned NULL instance of the '{context.BackgroundJob.Job.Type}' type.","messagePattern":"JobActivator returned NULL instance of the '(.+?)' type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Server/CoreBackgroundJobPerformer.cs","lineNumber":64,"sourceCode":"\n        public object Perform(PerformContext context)\n        {\n            using (var scope = _activator.BeginScope(context))\n            {\n                object instance = null;\n\n                if (context.BackgroundJob.Job == null)\n                {\n                    throw new InvalidOperationException(\"Can't perform a background job with a null job.\");\n                }\n                \n                if (!context.BackgroundJob.Job.Method.IsStatic)\n                {\n                    instance = scope.Resolve(context.BackgroundJob.Job.Type);\n\n                    if (instance == null)\n                    {\n                        throw new InvalidOperationException(\n                            $\"JobActivator returned NULL instance of the '{context.BackgroundJob.Job.Type}' type.\");\n                    }\n                }\n\n                var arguments = SubstituteArguments(context);\n                var result = InvokeMethod(context, instance, arguments);\n\n                return result;\n            }\n        }\n\n        internal static void HandleJobPerformanceException(Exception exception, IJobCancellationToken cancellationToken, [CanBeNull] BackgroundJob job)\n        {\n            if (exception is JobAbortedException)\n            {\n                // JobAbortedException exception should be thrown as-is to notify\n                // a worker that background job was aborted by a state change, and\n                // should NOT be re-queued.","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Server/CoreBackgroundJobPerformer.cs#L46-L82","documentation":"Thrown by CoreBackgroundJobPerformer.Perform when the JobActivator scope resolves to null for a non-static job type. Hangfire relies on the activator (DI integration) to construct the job's target class; returning null means the type could not be activated, which is always a configuration/registration problem.","triggerScenarios":"A non-static job method runs; scope.Resolve(job.Type) returns null. This happens when the JobActivator (e.g. AspNetCoreJobActivator, a DI-based activator) has no registration for the job's type.","commonSituations":"Forgetting to register the job class in the DI container when using scoped activators. Registering the implementation but resolving by a different type. A type that the activator's scope doesn't know about (e.g. registered in a different scope or assembly).","solutions":["Register the job's type in the DI container that backs the JobActivator (e.g. services.AddTransient<MyJob>() in ASP.NET Core).","Ensure the resolved type matches the type referenced in the job expression exactly.","Use a JobActivator that can create the type, or make the method static if no instance is needed."],"exampleFix":"// before\npublic class MyJob { public void Run() { } }\n// MyJob not registered → JobActivator returns null\n\n// after\n// Startup.cs / Program.cs\nservices.AddTransient<MyJob>();","handlingStrategy":"validation","validationCode":"// At startup, verify the job type is registered with the DI container backing the activator\nvar sp = app.ApplicationServices;\nif (sp.GetService(typeof(MyJob)) == null)\n    throw new InvalidOperationException(\"MyJob is not registered in DI.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register every non-static job class in the DI container.","Resolve by the exact type referenced in the job expression.","Use static methods for jobs that need no instance to avoid activation failures."],"tags":["performer","job-activator","dependency-injection","server"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}