dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'second')

Error message

Value cannot be null. (Parameter 'second')

What it means

This overload validates all 11 source sequences up front; a null 'second' makes it impossible to reference that source in the expression tree passed to the provider. The library throws ArgumentNullException immediately at composition time. Fix by supplying a real IObservable<TSecond>.

Solutions

  1. Verify the second argument is a concrete observable (Subject, Observable.Return, FromEventPattern, etc.) not null
  2. If the source may be absent, substitute Observable.Empty<TSecond>()
  3. Add a Debug.Assert or guard before composing the query

Example fix

// before
IObservable<string> second = null;
var q = first.CombineLatest(second, third, ...);
// after
IObservable<string> second = Observable.Empty<string>();
var q = first.CombineLatest(second, third, ...);
Defensive patterns

Strategy: validation

Validate before calling

if (first == null || second == null) throw new ArgumentNullException(nameof(second));

Type guard

static bool IsObservableSet(params IObservable<object>[] sources) => sources.All(s => s is not null);

Try / catch

try { var q = first.CombineLatest(second, ...); }
catch (ArgumentNullException ex) when (ex.ParamName == "second") { /* construct second before combining */ }

Prevention

When it happens

Trigger: Calling CombineLatest where the second argument (first IObservable<TSecond> non-IQbservable parameter) is null, e.g. null result from a service call that should return an observable.

Common situations: A repository or service method returning IObservable<T> returning null on a miss, uninitialized dependency injection field, or conditional wiring that skipped creating the source.

Related errors


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

Appendix: source

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

        /// <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>
        /// <param name="tenth">Tenth observable source.</param>
        /// <param name="eleventh">Eleventh 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" /> or <paramref name="eleventh" /> 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, TEleventh Eleventh)> CombineLatest<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TEighth, TNinth, TTenth, TEleventh>(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, IObservable<TEleventh> eleventh)
        {
            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));
            if (eleventh == null)
                throw new ArgumentNullException(nameof(eleventh));

View on GitHub (pinned to 94b5d5ab91)