dotnet/reactive · error · ArgumentNullException

sixth

Error message

sixth

What it means

System.Reactive throws ArgumentNullException with message "sixth" because the six-source CombineLatest overload in QbservableEx.Homoicon.cs requires all six source sequences to be non-null before it builds the MethodCallExpression via first.Provider.CreateQuery; the sixth (last) IObservable argument was null.

Solutions

  1. Provide a real IObservable<TSixth> — use Observable.Never<T>() or Observable.Empty<T>() when the sixth source is optional.
  2. Fix the conditional expression to always yield a sequence, e.g. flag ? stream : Observable.Never<T>().
  3. Verify the argument order after refactors so a non-null sequence occupies the sixth slot.

Example fix

// before
var combined = first.CombineLatest(second, third, fourth, fifth, enableSixth ? sixthStream : null);
// after
var sixth = enableSixth ? sixthStream : Observable.Never<TSixth>();
var combined = first.CombineLatest(second, third, fourth, fifth, sixth);
Defensive patterns

Strategy: validation

Validate before calling

if (sixth == null) throw new InvalidOperationException("sixth source must be a valid IObservable<TSixth>");
var combined = first.CombineLatest(second, third, fourth, fifth, sixth);

Type guard

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

Try / catch

try
{
    var combined = first.CombineLatest(second, third, fourth, fifth, sixth);
}
catch (ArgumentNullException ex) when (ex.ParamName == "sixth")
{
    var combined = first.CombineLatest(second, third, fourth, fifth, Observable.Never<TSixth>());
}

Prevention

When it happens

Trigger: Calling CombineLatest(first, second, third, fourth, fifth, sixth) with the sixth argument (IObservable<TSixth>) null.

Common situations: The last stream is optional and was passed conditionally (e.g. flag ? stream : null); a params-style helper assembled a list that ran short and a null slipped into the last slot; refactoring added the sixth argument without a corresponding producer.

Related errors


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

Appendix: source

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

        /// <param name="fifth">Fifth observable source.</param>
        /// <param name="sixth">Sixth 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" /> is null.</exception>
        public static IQbservable<(TFirst First, TSecond Second, TThird Third, TFourth Fourth, TFifth Fifth, TSixth Sixth)> CombineLatest<TFirst, TSecond, TThird, TFourth, TFifth, TSixth>(this IQbservable<TFirst> first, IObservable<TSecond> second, IObservable<TThird> third, IObservable<TFourth> fourth, IObservable<TFifth> fifth, IObservable<TSixth> sixth)
        {
            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));

            return first.Provider.CreateQuery<(TFirst First, TSecond Second, TThird Third, TFourth Fourth, TFifth Fifth, TSixth Sixth)>(
                Expression.Call(
                    null,
                    new Func<IQbservable<TFirst>, IObservable<TSecond>, IObservable<TThird>, IObservable<TFourth>, IObservable<TFifth>, IObservable<TSixth>, IQbservable<(TFirst First, TSecond Second, TThird Third, TFourth Fourth, TFifth Fifth, TSixth Sixth)>>(CombineLatest<TFirst, TSecond, TThird, TFourth, TFifth, TSixth>).Method,
                    first.Expression,
                    GetSourceExpression(second),
                    GetSourceExpression(third),
                    GetSourceExpression(fourth),
                    GetSourceExpression(fifth),
                    GetSourceExpression(sixth)
                )
            );
        }

        /// <summary>
        /// Merges the specified observable sequences into one observable sequence of tuple values whenever any of the observable sequences produces an element.
        /// </summary>

View on GitHub (pinned to 94b5d5ab91)