dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'first')

Error message

Value cannot be null. (Parameter 'first')

What it means

This is the tuple-returning nine-source CombineLatest overload; it checks every source argument up front and throws ArgumentNullException naming 'first' when the first observable is null. Rx treats null sequences as caller bugs and fails immediately at composition rather than at subscription. The XML docs on the method explicitly list 'first' among parameters that must not be null.

Solutions

  1. Initialize/pass a real IObservable<T> for the first argument before combining
  2. Coalesce with Observable.Empty<T>() or Observable.Never<T>() if absence is legitimate
  3. Fix the factory or DI registration that produced the null first stream
  4. Reorder or restructure to use the array-based overload when the argument list is built dynamically

Example fix

// before
var zipped = firstStream.CombineLatest(secondStream, thirdStream, /* ... */); // firstStream == null
// after
var stream = firstStream ?? Observable.Empty<WindowState>();
var zipped = stream.CombineLatest(secondStream, thirdStream, /* ... */);
Defensive patterns

Strategy: validation

Validate before calling

if (first == null) throw new InvalidOperationException("first 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, /* ... */); } catch (ArgumentNullException ex) when (ex.ParamName == "first") { /* initialize primary stream or fall back */ }

Prevention

When it happens

Trigger: Calling Observable.CombineLatest<TFirst,...,TNinth>(first,...,ninth) with first == null, usually when the primary stream comes from a service, cache, or config that returned null.

Common situations: Combining UI state streams where the primary view-model stream was not yet created; dependency-injection containers yielding null for an unregistered service; migration code that reordered arguments and shifted a null into the first slot.

Related errors


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

Appendix: source

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

        /// <typeparam name="TSixth">The type of the elements in the sixth source sequence.</typeparam>
        /// <typeparam name="TSeventh">The type of the elements in the seventh source sequence.</typeparam>
        /// <typeparam name="TEighth">The type of the elements in the eighth source sequence.</typeparam>
        /// <typeparam name="TNinth">The type of the elements in the ninth source sequence.</typeparam>
        /// <param name="first">First observable source.</param>
        /// <param name="second">Second observable source.</param>
        /// <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);

View on GitHub (pinned to 94b5d5ab91)