dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'first')

Error message

Value cannot be null. (Parameter 'first')

What it means

The 11-source CombineLatest overload for IQbservable requires every source sequence to be non-null because the expression tree built via first.Provider.CreateQuery must reference each argument. The library eagerly validates arguments with ArgumentNullException before constructing the expression. 'first' is null, meaning the IQbservable receiver you extended is null.

Solutions

  1. Ensure the IQbservable<T> receiver ('first') is created by a non-null query provider (e.g. Qbservable.Provider.Qbservable<T>) before calling CombineLatest
  2. Check every variable feeding the first argument for null before composing the query
  3. If sources may be optional, use Observable.Empty<T>().ToQbservable(provider) or a default sequence instead of null

Example fix

// before
IQbservable<int> first = null;
var q = first.CombineLatest(second, third, ..., eleventh);
// after
var first = Qbservable.Provider.Qbservable<int>(new[] { 0 });
var q = first.CombineLatest(second, third, ..., eleventh);
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

static bool IsNonNull<TSource>(IQbservable<TSource> q) => q is not null;

Try / catch

try { var q = first.CombineLatest(second, ...); }
catch (ArgumentNullException ex) when (ex.ParamName == "first") { /* supply a valid IQbservable source */ }

Prevention

When it happens

Trigger: Calling QbservableEx.CombineLatest with a null first argument, e.g. IQbservable<int> first = null; first.CombineLatest(obs2, obs3, ..., obs11); — typically the result of a LINQ chain or conditional that returned null.

Common situations: Assigning the result of a provider query that returned null, a method returning IQbservable<T> that falls through without a value, or passing an uninitialized field before the query pipeline is built.

Related errors


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

Appendix: source

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

        /// <typeparam name="TEleventh">The type of the elements in the eleventh 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>
        /// <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));

View on GitHub (pinned to 94b5d5ab91)