{"record":{"id":"4443f3f41f4c7b63","repo":"HangfireIO/Hangfire","slug":"output-parameters-are-not-supported-there-is-no-g","errorCode":null,"errorMessage":"Output parameters are not supported: there is no guarantee that specified method will be invoked inside the same process.","messagePattern":"Output parameters are not supported: there is no guarantee that specified method will be invoked inside the same process\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Common/Job.cs","lineNumber":520,"sourceCode":"\n            var parameters = method.GetParameters();\n\n            if (parameters.Length != argumentCount)\n            {\n                throw new ArgumentException(\n                    \"Argument count must be equal to method parameter count.\",\n                    argumentParameterName);\n            }\n\n            foreach (var parameter in parameters)\n            {\n                // There is no guarantee that specified method will be invoked\n                // in the same process. Therefore, output parameters and parameters\n                // passed by reference are not supported.\n\n                if (parameter.IsOut)\n                {\n                    throw new NotSupportedException(\n                        \"Output parameters are not supported: there is no guarantee that specified method will be invoked inside the same process.\");\n                }\n\n                if (parameter.ParameterType.IsByRef)\n                {\n                    throw new NotSupportedException(\n                        \"Parameters, passed by reference, are not supported: there is no guarantee that specified method will be invoked inside the same process.\");\n                }\n\n                var parameterTypeInfo = parameter.ParameterType.GetTypeInfo();\n                \n                if (parameterTypeInfo.IsSubclassOf(typeof(Delegate)) || parameterTypeInfo.IsSubclassOf(typeof(Expression)))\n                {\n                    throw new NotSupportedException(\n                        \"Anonymous functions, delegates and lambda expressions aren't supported in job method parameters: it's very hard to serialize them and all their scope in general.\");\n                }\n            }\n        }","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Common/Job.cs#L502-L538","documentation":"NotSupportedException thrown by Job.Validate when any parameter of the target method has parameter.IsOut == true (declared with the 'out' modifier). Hangfire serializes arguments and invokes methods in a separate process by reflection, but out parameters require a caller-provided storage location to receive the output — impossible across process boundaries. This is rejected at job-definition time before any storage interaction.","triggerScenarios":"Enqueuing () => service.Run(out result); a method declared as public void Run(out int x); using a library method with an out parameter as a job.","commonSituations":"Wrapping a Try-parse-style method (e.g., int.TryParse(out var n)) as a job; refactoring a method to add an out parameter; using third-party APIs that use out parameters.","solutions":["Remove the out parameter from the job method; return the value as the method's return type or via a result object.","Wrap the out-parameter method in a public method with plain parameters and enqueue the wrapper.","If the value is needed downstream, store it in a shared location (database/cache) keyed by job ID instead of an out param."],"exampleFix":"// before — out parameter, unsupported\npublic class Worker {\n    public void Run(out int result) { result = 42; }\n}\nBackgroundJob.Enqueue<Worker>(x => x.Run(out _));\n\n// after — return value\npublic class Worker {\n    public int Run() { return 42; }\n}\nBackgroundJob.Enqueue<Worker>(x => x.Run());","handlingStrategy":"validation","validationCode":"if (method.GetParameters().Any(p => p.IsOut))\n    throw new NotSupportedException(\"Job method has out parameters; remove them before creating the job.\");","typeGuard":"public static bool HasNoOutParameters(MethodInfo m)\n    => m != null && m.GetParameters().All(p => !p.IsOut);","tryCatchPattern":"try { BackgroundJob.Enqueue<T>(x => x.Work()); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Output parameters\")) { /* remove the out param, return the value instead */ }","preventionTips":["Never declare out parameters on job methods; return values via the return type.","Wrap out-parameter library calls in a public method with plain parameters.","Review method signatures during code review for out/ref modifiers."],"tags":["not-supported","job-definition","out-parameter","serialization"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}