dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'fourth')

Error message

Value cannot be null. (Parameter 'fourth')

What it means

The nine-source tuple CombineLatest overload throws ArgumentNullException for parameter 'fourth' when the fourth observable source is null. Arguments are validated in declaration order at composition time, so this error means the first three sources were fine and the fourth slot received null. This is part of Rx's documented contract that all source parameters are non-null.

Solutions

  1. Pass a non-null IObservable<TFourth> in the fourth position
  2. Replace with Observable.Empty<TFourth>() or Observable.Never<TFourth>() if the stream is optional
  3. Repair the initializer/registry responsible for the fourth stream
  4. Build the sources into an array, filter nulls, and use the params CombineLatest overload

Example fix

// before
var combined = first.CombineLatest(second, third, fourth, ...); // fourth == null
// after
var combined = first.CombineLatest(second, third, fourth ?? Observable.Empty<TFourth>(), ...);
Defensive patterns

Strategy: validation

Validate before calling

if (fourth == null) throw new InvalidOperationException("fourth stream must be initialized before CombineLatest");

Type guard

bool IsNonNull<T>(IObservable<T> s) => s is not null;

Try / catch

try { var combined = first.CombineLatest(second, third, fourth, /* ... */); } catch (ArgumentNullException ex) when (ex.ParamName == "fourth") { /* supply default stream */ }

Prevention

When it happens

Trigger: Calling the 9-argument Observable.CombineLatest with null in the fourth positional argument (IObservable<TFourth>).

Common situations: Dashboard-style UIs combining many view streams where one fragment failed to initialize; plugin systems where an optional module contributed a null stream; manual argument expansion from a list that was shorter than expected.

Related errors


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

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Multiple.CombineLatest.cs:1449

        /// <param name="third">Third observable source.</param>
        /// <param name="fourth">Fourth observable source.</param>
        /// <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>
        /// <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"/> is null.</exception>
        public static IObservable<(TFirst First, TSecond Second, TThird Third, TFourth Fourth, TFifth Fifth, TSixth Sixth, TSeventh Seventh, TEighth Eighth, TNinth Ninth)> CombineLatest<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TEighth, TNinth>(this IObservable<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)
        {
            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));

            return s_impl.CombineLatest(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth);
        }

        /// <summary>
        /// Merges the specified observable sequences into one observable sequence of tuple values whenever any of the observable sequences produces an element.
        /// </summary>
        /// <typeparam name="TFirst">The type of the elements in the first source sequence.</typeparam>

View on GitHub (pinned to 94b5d5ab91)