HangfireIO/Hangfire · error · ArgumentNullException
value
Error message
value
What it means
Thrown by the BackgroundExecutionOptions.RetryDelay setter (internal) when the assigned Func<int, TimeSpan> is null. RetryDelay computes the back-off between retry attempts in the execution loop; a null function would NRE on every exception.
Source
Thrown at src/Hangfire.Core/Processing/BackgroundExecutionOptions.cs:73
}
}
public TimeSpan StillErrorThreshold
{
get { return _stillErrorThreshold; }
set
{
if (value < TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(value), "Value should be greater than or equal to TimeSpan.Zero");
_stillErrorThreshold = value;
}
}
public Func<int, TimeSpan> RetryDelay
{
get { return _retryDelay; }
set
{
if (value == null) throw new ArgumentNullException(nameof(value));
_retryDelay = value;
}
}
internal static TimeSpan GetBackOffMultiplier(int retryAttemptNumber)
{
//exponential/random retry back-off.
var rand = new Random(Guid.NewGuid().GetHashCode());
var nextTry = rand.Next(
(int)Math.Pow(retryAttemptNumber, 2), (int)Math.Pow(retryAttemptNumber, 2) + 1);
return TimeSpan.FromSeconds(Math.Min(nextTry, DefaultMaxAttemptDelay.TotalSeconds));
}
}
}
View on GitHub (pinned to c236dd0f93)
Solutions
- Assign a non-null Func<int, TimeSpan> — use BackgroundExecutionOptions.GetBackOffMultiplier for the default exponential back-off.
- If you need a constant delay, supply `_ => TimeSpan.FromSeconds(5)` rather than null.
- Guard configuration: replace null with the default function before assignment.
Example fix
// before options.RetryDelay = null; // after options.RetryDelay = attempt => TimeSpan.FromSeconds(Math.Min(attempt * attempt, 300));
Defensive patterns
Strategy: validation
Validate before calling
options.RetryDelay = configuredDelay ?? BackgroundExecutionOptions.GetBackOffMultiplier;
Prevention
- Never assign null to RetryDelay — supply a real Func<int, TimeSpan>.
- Use GetBackOffMultiplier for the built-in exponential back-off.
- For constant delays use `_ => TimeSpan.FromSeconds(n)`.
When it happens
Trigger: Assigning options.RetryDelay = null. Reached when configuration explicitly clears the retry-delay function or a binding fails to resolve it.
Common situations: Code that sets RetryDelay conditionally and falls through to null; a refactor that replaced the function with null instead of a no-op; deserialisation that omits the function.
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/246d96431ff818fe.
Report an issue: GitHub.