dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'source5')
Error message
Value cannot be null. (Parameter 'source5')
What it means
Observable.CombineLatest (5-source overload) throws ArgumentNullException when the resultSelector delegate is null. The selector combines the latest value of each of the five sources into a result; Rx checks it eagerly at call time with parameter name 'resultSelector'.
Solutions
- Pass a concrete non-null Func<TSource1,...,TSource5,TResult> as the last argument
- If the projection is optional, supply a default projection (e.g. tuple or array of latest values) instead of null
- Check the code path that builds the selector and make it return a fallback delegate rather than null
- Validate the selector before composing: if (resultSelector == null) throw new InvalidOperationException("No projection configured")
Example fix
// before Func<int, int, int, int, int, string> selector = _config.Mode == "sum" ? Sum : null; var combined = Observable.CombineLatest(a, b, c, d, e, selector); // throws in default mode // after Func<int, int, int, int, int, string> selector = _config.Mode == "sum" ? Sum : Default; var combined = Observable.CombineLatest(a, b, c, d, e, selector);
Defensive patterns
Strategy: validation
Validate before calling
if (resultSelector is null) throw new ArgumentNullException(nameof(resultSelector)); var combined = Observable.CombineLatest(source1, source2, source3, source4, source5, resultSelector);
Type guard
static bool IsUsable<T1,T2,T3,T4,T5,TResult>(Func<T1,T2,T3,T4,T5,TResult>? f) => f is not null;
Try / catch
try
{
combined = Observable.CombineLatest(s1, s2, s3, s4, s5, resultSelector);
}
catch (ArgumentNullException ex) when (ex.ParamName == "resultSelector")
{
resultSelector = DefaultProjection;
combined = Observable.CombineLatest(s1, s2, s3, s4, s5, resultSelector);
} Prevention
- Always provide a concrete projection; use _ => default or a tuple builder when no transformation is needed
- When resolving selectors dynamically, fall back to a default delegate rather than null
- Type nullable Func fields and coalesce at use site: selector ?? DefaultSelector
- Cover selector-resolution branches with tests so null paths are caught early
When it happens
Trigger: Calling Observable.CombineLatest(s1, s2, s3, s4, s5, null) — e.g. the selector was computed at runtime, returned null from a factory, or a conditional expression like (useA ? selA : selB) yielded null.
Common situations: Building query DSLs where the projection is optional; reflection-based or config-driven composition where the selector method name failed to resolve to a delegate; nullable Func fields not yet initialized.
Related errors
- action (Parameter 'action')
- action
- Value cannot be null. (Parameter 'selector')
- Value cannot be null. (Parameter 'newCollector')
- Value cannot be null. (Parameter 'merge')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/ece677f5be5882bd.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Multiple.CombineLatest.cs:138
if (source2 == null)
{
throw new ArgumentNullException(nameof(source2));
}
if (source3 == null)
{
throw new ArgumentNullException(nameof(source3));
}
if (source4 == null)
{
throw new ArgumentNullException(nameof(source4));
}
if (source5 == null)
{
throw new ArgumentNullException(nameof(source5));
}
if (resultSelector == null)
{
throw new ArgumentNullException(nameof(resultSelector));
}
return s_impl.CombineLatest(source1, source2, source3, source4, source5, resultSelector);
}
/// <summary>
/// Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.
/// </summary>
/// <typeparam name="TSource1">The type of the elements in the first source sequence.</typeparam>
/// <typeparam name="TSource2">The type of the elements in the second source sequence.</typeparam>
/// <typeparam name="TSource3">The type of the elements in the third source sequence.</typeparam>
/// <typeparam name="TSource4">The type of the elements in the fourth source sequence.</typeparam>
/// <typeparam name="TSource5">The type of the elements in the fifth source sequence.</typeparam>View on GitHub (pinned to 94b5d5ab91)