{"record":{"id":"a3bae6a45fef9275","repo":"HangfireIO/Hangfire","slug":"an-exception-occurred-during-performance-of-the-jo","errorCode":null,"errorMessage":"An exception occurred during performance of the job.","messagePattern":"An exception occurred during performance of the job\\.","errorType":"exception","errorClass":"JobPerformanceException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Server/CoreBackgroundJobPerformer.cs","lineNumber":105,"sourceCode":"            {\n                // OperationCanceledException exception is thrown because \n                // ServerJobCancellationWatcher has detected the job was aborted.\n                throw new JobAbortedException();\n            }\n\n            if (exception is OperationCanceledException && cancellationToken.ShutdownToken.IsCancellationRequested)\n            {\n                // OperationCanceledException exceptions are treated differently from\n                // others, when ShutdownToken's cancellation was requested, to notify\n                // a worker that job performance was aborted by a shutdown request,\n                // and a job identifier should BE re-queued.\n                ExceptionDispatchInfo.Capture(exception).Throw();\n                throw exception;\n            }\n\n            // Other exceptions are wrapped with JobPerformanceException to preserve a\n            // shallow stack trace without Hangfire methods.\n            throw new JobPerformanceException(\n                \"An exception occurred during performance of the job.\",\n                exception, job?.Id);\n        }\n\n        private object InvokeMethod(PerformContext context, object instance, object[] arguments)\n        {\n            if (context.BackgroundJob.Job == null) return null;\n\n            try\n            {\n                var methodInfo = context.BackgroundJob.Job.Method;\n                var method = new BackgroundJobMethod(methodInfo, instance, arguments);\n                var returnType = methodInfo.ReturnType;\n\n                if (returnType.IsTaskLike(out var getTaskFunc))\n                {\n                    if (_taskScheduler != null)\n                    {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Server/CoreBackgroundJobPerformer.cs#L87-L123","documentation":"Thrown by CoreBackgroundJobPerformer.HandleJobPerformanceException as a JobPerformanceException wrapping any non-cancellation, non-abort exception raised while executing the job method. Hangfire wraps user exceptions to preserve a shallow stack trace and to mark the job failed. The original exception is the InnerException.","triggerScenarios":"The job method (or an async Task it returns) throws any exception that is not a JobAbortedException or a relevant OperationCanceledException. The performer catches it and rethrows wrapped.","commonSituations":"The job method throws due to a bug, null reference, business-rule violation, network error, DB constraint, etc. Any unhandled exception in the job body surfaces this way.","solutions":["Inspect InnerException of the JobPerformanceException to find the real cause and fix the job code.","Add try/catch inside the job method to handle expected exceptions and avoid polluting the failed-jobs list.","Configure AutomaticRetryAttribute to retry transient failures and FailedState thresholds appropriately."],"exampleFix":"// before\npublic void Run()\n{\n    var data = _repo.Get(id); // may throw\n    Process(data.Value);\n}\n\n// after\npublic void Run()\n{\n    try\n    {\n        var data = _repo.Get(id);\n        Process(data.Value);\n    }\n    catch (NotFoundException ex)\n    {\n        _logger.Warn(ex, \"item not found, skipping\");\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In the job method, handle expected exceptions\npublic void Run()\n{\n    try { /* work */ }\n    catch (TransientException) { throw; } // let Hangfire retry\n    catch (BusinessException ex) { _logger.Warn(ex, \"skipped\"); }\n}","preventionTips":["Inspect the InnerException of JobPerformanceException to find the real cause.","Handle expected exceptions inside the job method to avoid failed-state churn.","Use [AutomaticRetry] for transient failures and tune retry counts."],"tags":["performer","job-execution","exception-wrapping","server"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}