dotnet/reactive · error · ArgumentNullException
throw new ArgumentNullException(nameof(second))
Error message
throw new ArgumentNullException(nameof(second))
What it means
In the Qbservable (expression-tree) ForkJoin, the second observable sequence is null; the provider validates it because the IQueryable expression for the parallel last-element join cannot be built with a missing operand. Fix: pass a non-null IQbservable/IObservable for the second argument.
Solutions
- Supply a non-null IObservable as second
- Null-check second before calling ForkJoin
- Replace null with Observable.Empty<TSource2>() if 'no source' is intended
Example fix
// before first.ForkJoin(null, (a, b) => a + b); // after first.ForkJoin(second ?? Observable.Empty<int>().AsQbservable(), (a, b) => a + b);
Defensive patterns
Strategy: validation
Validate before calling
if (second is null) throw new ArgumentNullException(nameof(second));
Type guard
bool IsValidSecond<T>(IObservable<T> o) => o is not null;
Try / catch
try { var q = first.ForkJoin(second, selector); } catch (ArgumentNullException ex) when (ex.ParamName == "second") { /* handle null second */ } Prevention
- Substitute Observable.Empty for absent sources instead of null
- Null-check observables received from external services
When it happens
Trigger: Calling first.ForkJoin(null, resultSelector) or passing a null observable variable as the second source.
Common situations: A source observable that is null because an optional service or config-driven producer did not create it.
Related errors
- throw new ArgumentNullException(nameof(first))
- throw new ArgumentNullException(nameof(resultSelector))
- throw new ArgumentNullException(nameof(sources))
- Value cannot be null. (Parameter 'fourteenth')
- Value cannot be null. (Parameter 'thirteenth')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/b37e921eb869a7df.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs:1148
/// <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
/// <summary>
/// Returns an observable sequence that is the result of invoking the selector on the source sequence, without sharing subscriptions.View on GitHub (pinned to 94b5d5ab91)