dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'fourth')
Error message
Value cannot be null. (Parameter 'fourth')
What it means
ArgumentNullException with message "Value cannot be null. (Parameter 'fourth')" is thrown by the 10-source CombineLatest overload when the fourth source sequence is null. Like all Rx operators, CombineLatest requires non-null source sequences; the guard at QbservableEx.Homoicon.cs:413-414 runs before the query expression tree is created via first.Provider.CreateQuery.
Solutions
- Supply a valid IObservable<TFourth> instance; substitute Observable.Empty<TFourth>() or Observable.Never<TFourth>() when no stream is available.
- Trace and fix the code path that assigns null to the fourth source (failed factory, missing DI registration).
- Restructure the call to a lower-arity CombineLatest overload if the fourth source is optional.
Example fix
// before var combined = first.CombineLatest(second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth); // after var combined = first.CombineLatest(second, third, fourth ?? Observable.Empty<TFourth>(), fifth, sixth, seventh, eighth, ninth, tenth);
Defensive patterns
Strategy: validation
Validate before calling
if (fourth is null) throw new InvalidOperationException("fourth source must be a non-null IObservable<TFourth>");
// or: fourth ??= Observable.Empty<TFourth>(); Type guard
static bool IsValidSource<T>(IObservable<T>? source) => source is not null;
Try / catch
try
{
var combined = first.CombineLatest(second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth);
}
catch (ArgumentNullException ex) when (ex.ParamName == "fourth")
{
// handle missing fourth source
} Prevention
- Audit pipeline builders so skipped/failed stream creation yields Empty, not null.
- Coalesce with ?? Observable.Empty<T>() at the call site.
- Use nullable reference type annotations to surface possible nulls at compile time.
When it happens
Trigger: Calling QbservableEx.CombineLatest with the fourth argument (IObservable<TFourth>) set to null; the check executes after the first three sources validate successfully.
Common situations: A pipeline built dynamically where the fourth stream's creation step was skipped or failed silently; null returned from a conditional stream builder; uninitialized class members holding the sources.
Related errors
- Value cannot be null. (Parameter 'third')
- Value cannot be null. (Parameter 'fifth')
- Value cannot be null. (Parameter 'sixth')
- Value cannot be null. (Parameter 'seventh')
- Value cannot be null. (Parameter 'eighth')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/ff7d18de351f696f.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs:413
/// <param name="fifth">Fifth observable source.</param>
/// <param name="sixth">Sixth observable source.</param>
/// <param name="seventh">Seventh observable source.</param>
/// <param name="eighth">Eighth observable source.</param>
/// <param name="ninth">Ninth observable source.</param>
/// <param name="tenth">Tenth observable source.</param>
/// <returns>An observable sequence containing the result of combining elements of the sources using tuple values.</returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="first" /> or <paramref name="second" /> or <paramref name="third" /> or <paramref name="fourth" /> or <paramref name="fifth" /> or <paramref name="sixth" /> or <paramref name="seventh" /> or <paramref name="eighth" /> or <paramref name="ninth" /> or <paramref name="tenth" /> is null.</exception>
public static IQbservable<(TFirst First, TSecond Second, TThird Third, TFourth Fourth, TFifth Fifth, TSixth Sixth, TSeventh Seventh, TEighth Eighth, TNinth Ninth, TTenth Tenth)> CombineLatest<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TEighth, TNinth, TTenth>(this IQbservable<TFirst> first, IObservable<TSecond> second, IObservable<TThird> third, IObservable<TFourth> fourth, IObservable<TFifth> fifth, IObservable<TSixth> sixth, IObservable<TSeventh> seventh, IObservable<TEighth> eighth, IObservable<TNinth> ninth, IObservable<TTenth> tenth)
{
if (first == null)
throw new ArgumentNullException(nameof(first));
if (second == null)
throw new ArgumentNullException(nameof(second));
if (third == null)
throw new ArgumentNullException(nameof(third));
if (fourth == null)
throw new ArgumentNullException(nameof(fourth));
if (fifth == null)
throw new ArgumentNullException(nameof(fifth));
if (sixth == null)
throw new ArgumentNullException(nameof(sixth));
if (seventh == null)
throw new ArgumentNullException(nameof(seventh));
if (eighth == null)
throw new ArgumentNullException(nameof(eighth));
if (ninth == null)
throw new ArgumentNullException(nameof(ninth));
if (tenth == null)
throw new ArgumentNullException(nameof(tenth));
return first.Provider.CreateQuery<(TFirst First, TSecond Second, TThird Third, TFourth Fourth, TFifth Fifth, TSixth Sixth, TSeventh Seventh, TEighth Eighth, TNinth Ninth, TTenth Tenth)>(
Expression.Call(
null,
new Func<IQbservable<TFirst>, IObservable<TSecond>, IObservable<TThird>, IObservable<TFourth>, IObservable<TFifth>, IObservable<TSixth>, IObservable<TSeventh>, IObservable<TEighth>, IObservable<TNinth>, IObservable<TTenth>, IQbservable<(TFirst First, TSecond Second, TThird Third, TFourth Fourth, TFifth Fifth, TSixth Sixth, TSeventh Seventh, TEighth Eighth, TNinth Ninth, TTenth Tenth)>>(CombineLatest<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TEighth, TNinth, TTenth>).Method,
first.Expression,View on GitHub (pinned to 94b5d5ab91)