dotnet/reactive · error · ArgumentNullException

throw new ArgumentNullException(nameof(first))

Error message

throw new ArgumentNullException(nameof(first))

What it means

The two-source ForkJoin overload throws ArgumentNullException when the first IQbservable<TSource1> is null. The instance's Provider property is needed to build the result query, so null is rejected up front.

Solutions

  1. Ensure the first argument is a valid non-null IQbservable
  2. Null-check the qbservable before chaining ForkJoin
  3. Trace why the upstream query construction returned null

Example fix

// before
IQbservable<int> first = null;
var q = first.ForkJoin(second, (a, b) => a + b);
// after
if (first == null) throw new InvalidOperationException("first is null");
var q = first.ForkJoin(second, (a, b) => a + b);
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

bool IsValidFirst<T>(IQbservable<T> q) => q is not null;

Try / catch

try { var q = first.ForkJoin(second, selector); } catch (ArgumentNullException ex) when (ex.ParamName == "first") { /* handle null first */ }

Prevention

When it happens

Trigger: Calling first.ForkJoin(second, resultSelector) where the extension method is invoked on a null IQbservable reference (allowed in C# for extension methods until the guard runs).

Common situations: A LINQ query variable that was null because an earlier qbservable factory returned null, or calling the static form ForkJoin(null, second, selector).

Related errors


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

Appendix: source

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

#if !STABLE
        /// <summary>
        /// Runs two observable sequences in parallel and combines their last elements.
        /// </summary>
        /// <typeparam name="TSource1">The type of the elements in the first source sequence.</typeparam>
        /// <typeparam name="TSource2">The type of the elements in the second source sequence.</typeparam>
        /// <typeparam name="TResult">The type of the elements in the result sequence, returned by the selector function.</typeparam>
        /// <param name="first">First observable sequence.</param>
        /// <param name="second">Second observable sequence.</param>
        /// <param name="resultSelector">Result selector function to invoke with the last elements of both sequences.</param>
        /// <returns>An observable sequence with the result of calling the selector function with the last elements of both input sequences.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="first" /> or <paramref name="second" /> or <paramref name="resultSelector" /> is null.</exception>
        [Experimental]
        public static IQbservable<TResult> ForkJoin<TSource1, TSource2, TResult>(this IQbservable<TSource1> first, IObservable<TSource2> second, Expression<Func<TSource1, TSource2, TResult>> resultSelector)
        {
            if (first == null)
                throw new ArgumentNullException(nameof(first));
            if (second == null)
                throw new ArgumentNullException(nameof(second));
            if (resultSelector == null)
                throw new ArgumentNullException(nameof(resultSelector));

            return first.Provider.CreateQuery<TResult>(
                Expression.Call(
                    null,
                    new Func<IQbservable<TSource1>, IObservable<TSource2>, Expression<Func<TSource1, TSource2, TResult>>, IQbservable<TResult>>(ForkJoin<TSource1, TSource2, TResult>).Method,
                    first.Expression,
                    GetSourceExpression(second),
                    resultSelector
                )
            );
        }
#endif

#if !STABLE

View on GitHub (pinned to 94b5d5ab91)