HangfireIO/Hangfire · error · NotSupportedException
Output parameters are not supported: there is no guarantee t
Error message
Output parameters are not supported: there is no guarantee that specified method will be invoked inside the same process.
What it means
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.
Source
Thrown at src/Hangfire.Core/Common/Job.cs:520
var parameters = method.GetParameters();
if (parameters.Length != argumentCount)
{
throw new ArgumentException(
"Argument count must be equal to method parameter count.",
argumentParameterName);
}
foreach (var parameter in parameters)
{
// There is no guarantee that specified method will be invoked
// in the same process. Therefore, output parameters and parameters
// passed by reference are not supported.
if (parameter.IsOut)
{
throw new NotSupportedException(
"Output parameters are not supported: there is no guarantee that specified method will be invoked inside the same process.");
}
if (parameter.ParameterType.IsByRef)
{
throw new NotSupportedException(
"Parameters, passed by reference, are not supported: there is no guarantee that specified method will be invoked inside the same process.");
}
var parameterTypeInfo = parameter.ParameterType.GetTypeInfo();
if (parameterTypeInfo.IsSubclassOf(typeof(Delegate)) || parameterTypeInfo.IsSubclassOf(typeof(Expression)))
{
throw new NotSupportedException(
"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.");
}
}
}View on GitHub (pinned to c236dd0f93)
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.
Example fix
// before — out parameter, unsupported
public class Worker {
public void Run(out int result) { result = 42; }
}
BackgroundJob.Enqueue<Worker>(x => x.Run(out _));
// after — return value
public class Worker {
public int Run() { return 42; }
}
BackgroundJob.Enqueue<Worker>(x => x.Run()); Defensive patterns
Strategy: validation
Validate before calling
if (method.GetParameters().Any(p => p.IsOut))
throw new NotSupportedException("Job method has out parameters; remove them before creating the job."); Type guard
public static bool HasNoOutParameters(MethodInfo m)
=> m != null && m.GetParameters().All(p => !p.IsOut); Try / catch
try { BackgroundJob.Enqueue<T>(x => x.Work()); }
catch (NotSupportedException ex) when (ex.Message.Contains("Output parameters")) { /* remove the out param, return the value instead */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Parameters, passed by reference, are not supported: there is
- Only public methods can be invoked in the background. Ensure
- Job method can not contain unassigned generic type parameter
- Global methods are not supported. Use class methods instead.
- Async void methods are not supported. Use async Task instead
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/4443f3f41f4c7b63.
Report an issue: GitHub.