{"record":{"id":"a0e11b986a4a049b","repo":"HangfireIO/Hangfire","slug":"an-exception-occurred-during-job-activation","errorCode":null,"errorMessage":"An exception occurred during job activation.","messagePattern":"An exception occurred during job activation\\.","errorType":"exception","errorClass":"JobPerformanceException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Obsolete/Job.Obsolete.cs","lineNumber":91,"sourceCode":"        }\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();\n                var result = new List<object>(Args.Count);\n\n                for (var i = 0; i < parameters.Length; i++)\n                {\n                    var parameter = parameters[i];\n                    var argument = Args[i];\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Obsolete/Job.Obsolete.cs#L73-L109","documentation":"Thrown as JobPerformanceException (message 'An exception occurred during job activation.') wrapping any catchable exception raised while the JobActivator tried to instantiate the job type. The obsolete Activate() method at lines 78-94 catches the inner exception and rethrows it inside a JobPerformanceException so the worker pipeline treats activation failures uniformly with other performance errors.","triggerScenarios":"Job.Perform (obsolete) calls Activate(activator); activator.ActivateJob(Type) throws — e.g. MissingMethodException (no matching constructor), a constructor that throws, a DI resolution exception, or a type-load failure. The catch filter (ex.IsCatchableExceptionType) wraps it into JobPerformanceException.","commonSituations":"The job type lacks a public parameterless constructor and no DI activator is configured; the job's constructor throws (e.g. reads config that is missing, opens a connection that fails); the type fails to load due to a missing dependency assembly; a scoped DI service is resolved outside its lifetime scope.","solutions":["Inspect the InnerException of the JobPerformanceException to find the real activation error and address it (register the service, fix the constructor, add the dependency).","Ensure the job type has a resolvable constructor — either public parameterless for the default activator, or registered with the DI container for a DI activator.","If the constructor performs work that can fail, move that work into the job method body so activation stays cheap and reliable."],"exampleFix":"// before — constructor throws, activation fails\npublic MyJob() { _conn = new SqlConnection(_cs); _conn.Open(); }\n\n// after — move failure-prone work into the method\npublic MyJob() { }\npublic void Run() { using var c = new SqlConnection(_cs); c.Open(); ... }","handlingStrategy":"try-catch","validationCode":"// No pre-check reliably predicts constructor failure; ensure the type is\n// registered and has a resolvable ctor before performing.\nservices.AddTransient<MyJob>();","typeGuard":null,"tryCatchPattern":"try { job.Perform(activator, token); }\ncatch (JobPerformanceException ex) when (ex.Message.Contains(\"during job activation\"))\n{\n    logger.LogError(ex.InnerException, \"Activation failed for {Job}\", job.Type);\n}","preventionTips":["Keep job constructors cheap — no I/O, no config reads that can fail.","Register job types in DI and resolve via a proper activator.","Inspect InnerException to find the real cause."],"tags":["job-performance","di","job-activator","obsolete","exception-wrapping"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}