HangfireIO/Hangfire · error · ArgumentNullException
source
Error message
source
What it means
Thrown by the MoreEnumerable.Pairwise extension method (part of Hangfire's vendored MoreLinq) when the source sequence is null. Pairwise projects consecutive pairs of elements using a selector function; a null source sequence cannot be enumerated.
Source
Thrown at src/Hangfire.Core/MoreLinq/MoreEnumerable.Pairwise.cs:53
/// <param name="resultSelector">A transform function to apply to
/// each pair of sequence.</param>
/// <returns>
/// Returns the resulting sequence.
/// </returns>
/// <remarks>
/// This operator uses deferred execution and streams its results.
/// </remarks>
/// <example>
/// <code>
/// int[] numbers = { 123, 456, 789 };
/// IEnumerable<int> result = numbers.Pairwise(5, (a, b) => a + b);
/// </code>
/// The <c>result</c> variable, when iterated over, will yield
/// 579 and 1245, in turn.
/// </example>
public static IEnumerable<TResult> Pairwise<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TSource, TResult> resultSelector)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));
return PairwiseImpl(source, resultSelector);
}
private static IEnumerable<TResult> PairwiseImpl<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TSource, TResult> resultSelector)
{
Debug.Assert(source != null);
Debug.Assert(resultSelector != null);
using (var e = source.GetEnumerator())
{
if (!e.MoveNext())
yield break;
var previous = e.Current;
while (e.MoveNext())
{
yield return resultSelector(previous, e.Current);View on GitHub (pinned to c236dd0f93)
Solutions
- Ensure the source sequence is non-null; use Enumerable.Empty<T>() instead of null for empty sequences
- Add a null check before calling Pairwise
- If the source comes from a method that may return null, coalesce with ?? Enumerable.Empty<T>()
Example fix
// before IEnumerable<int> items = GetItems(); // returns null var pairs = items.Pairwise((a, b) => a + b); // after var items = GetItems() ?? Enumerable.Empty<int>(); var pairs = items.Pairwise((a, b) => a + b);
Defensive patterns
Strategy: validation
Validate before calling
var safeSource = source ?? Enumerable.Empty<TSource>(); var pairs = safeSource.Pairwise(resultSelector);
Type guard
source != null
Prevention
- Return Enumerable.Empty<T>() instead of null from methods that feed Pairwise
- Use the null-coalescing operator (??) to provide an empty fallback
- Validate collection-returning methods for null before passing to LINQ operators
When it happens
Trigger: Calling null.Pairwise(selector) or someCollection.Pairwise(selector) where someCollection is null. The check happens eagerly at call time, before deferred execution begins.
Common situations: An internal Hangfire code path passes a null collection to Pairwise (e.g., a method returning null instead of an empty enumerable), or application code using Hangfire's vendored MoreLinq Pairwise on a null reference.
Related errors
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/7d26036b98434597.
Report an issue: GitHub.