{"record":{"id":"e508ea2e83c1cdc1","repo":"HangfireIO/Hangfire","slug":"an-exception-occurred-during-arguments-deserializa","errorCode":null,"errorMessage":"An exception occurred during arguments deserialization.","messagePattern":"An exception occurred during arguments deserialization\\.","errorType":"exception","errorClass":"JobPerformanceException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Obsolete/Job.Obsolete.cs","lineNumber":128,"sourceCode":"                    object value;\n\n                    if (typeof(IJobCancellationToken).GetTypeInfo().IsAssignableFrom(parameter.ParameterType.GetTypeInfo()))\n                    {\n                        value = cancellationToken;\n                    }\n                    else\n                    {\n                        value = argument;\n                    }\n\n                    result.Add(value);\n                }\n\n                return result.ToArray();\n            }\n            catch (Exception ex) when (ex.IsCatchableExceptionType())\n            {\n                throw new JobPerformanceException(\n                    \"An exception occurred during arguments deserialization.\",\n                    ex);\n            }\n        }\n\n        [Obsolete(\"Will be removed in 2.0.0\")]\n        private object InvokeMethod(object instance, object[] deserializedArguments, IJobCancellationToken cancellationToken)\n        {\n            try\n            {\n                return Method.Invoke(instance, deserializedArguments);\n            }\n            catch (TargetInvocationException ex)\n            {\n                CoreBackgroundJobPerformer.HandleJobPerformanceException(ex.InnerException, cancellationToken, null);\n                throw;\n            }\n        }","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Obsolete/Job.Obsolete.cs#L110-L146","documentation":"Thrown as JobPerformanceException (message 'An exception occurred during arguments deserialization.') wrapping any catchable exception raised while the obsolete GetArguments method reconstructs the argument list for method invocation. The method iterates the job's parameters and matches them against stored Args; any failure (index out of range, type mismatch, nullability) is wrapped and rethrown at lines 126-131.","triggerScenarios":"Job.Perform (obsolete) calls GetArguments(cancellationToken) which iterates Method.GetParameters() and indexes into Args. An exception occurs if the stored argument count does not match the method's parameter count, a stored argument cannot be assigned to its parameter type, or the method signature changed since the job was enqueued (e.g. parameter added/removed, type changed).","commonSituations":"A stored job references an older method signature after a deployment that changed parameter count or types; serialization produced a value incompatible with the parameter (e.g. a JSON deserialization returning null for a non-nullable struct); a corrupt or manually-edited job state with truncated arguments.","solutions":["Inspect the InnerException of the JobPerformanceException to identify the exact argument/parameter mismatch.","Ensure deployed job method signatures match the jobs already in storage — avoid changing parameter counts/types on methods referenced by pending jobs, or clear the affected jobs.","If you must change a signature, version the method (new name) or drain the queue before deploying."],"exampleFix":"// before — method signature changed, stored args no longer match\npublic void Send(string to) { ... }\n// pending job stored with 2 args fails deserialization\n\n// after — keep the old overload and add a new method\npublic void Send(string to) { ... }\npublic void SendWithTemplate(string to, string template) { ... }","handlingStrategy":"try-catch","validationCode":"// Validate stored argument count matches the method before performing:\nif (job.Method.GetParameters().Length != job.Args.Count)\n    throw new InvalidOperationException(\"Stored args do not match method signature.\");","typeGuard":null,"tryCatchPattern":"try { job.Perform(activator, token); }\ncatch (JobPerformanceException ex) when (ex.Message.Contains(\"arguments deserialization\"))\n{\n    logger.LogError(ex.InnerException, \"Arg deserialization failed for {Method}\", job.Method);\n}","preventionTips":["Do not change job method signatures while compatible jobs are still queued — version the method or drain the queue.","Inspect InnerException to pinpoint the mismatched parameter.","Avoid manually editing stored job arguments."],"tags":["job-performance","serialization","argument-mismatch","obsolete","exception-wrapping"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}