dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'fifth')

Error message

Value cannot be null. (Parameter 'fifth')

What it means

ArgumentNullException with message "Value cannot be null. (Parameter 'fifth')" is thrown by the 10-source CombineLatest overload when the fifth source sequence is null. The method's eager argument validation ensures all ten sources are non-null before building the Expression.Call tree for the IQbservableProvider, consistent with the documented exception contract on the method.

Solutions

  1. Provide a non-null IObservable<TFifth>; coalesce with Observable.Empty<TFifth>() if absence is expected.
  2. Fix the stream factory or initialization logic so the fifth source is never null.
  3. Use a 9-source CombineLatest overload to omit the fifth source instead of passing null.

Example fix

// before
var combined = first.CombineLatest(second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth);
// after
var combined = first.CombineLatest(second, third, fourth, fifth ?? Observable.Empty<TFifth>(), sixth, seventh, eighth, ninth, tenth);
Defensive patterns

Strategy: validation

Validate before calling

if (fifth is null) throw new InvalidOperationException("fifth source must be a non-null IObservable<TFifth>");
// or: fifth ??= Observable.Empty<TFifth>();

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 == "fifth")
{
    // handle missing fifth source
}

Prevention

When it happens

Trigger: Calling QbservableEx.CombineLatest with fifth == null; the guard at QbservableEx.Homoicon.cs:415-416 fires once sources one through four have passed validation.

Common situations: Combining UI or telemetry streams where one stream provider returned null; refactoring that changed a stream from an initialized Subject to a nullable field; passing null instead of an Empty sequence for an optional source.

Related errors


AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15). Data as JSON: /api/errors/9e7e21f83bc22d98. Report an issue: GitHub.

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs:415

        /// <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,
                    GetSourceExpression(second),
                    GetSourceExpression(third),

View on GitHub (pinned to 94b5d5ab91)