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

  1. Assign a non-null Func<int, TimeSpan> — use BackgroundExecutionOptions.GetBackOffMultiplier for the default exponential back-off.
  2. If you need a constant delay, supply `_ => TimeSpan.FromSeconds(5)` rather than null.
  3. 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

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.