dotnet/reactive · error · ArgumentNullException
first
Error message
first
What it means
QbservableEx.CombineLatest<TFirst,TSecond>(IQbservable<TFirst>, IObservable<TSecond>) throws ArgumentNullException when the first (qbservable) source is null. The method uses first.Provider and first.Expression to build the resulting query, so a null first sequence is rejected before expression construction.
Solutions
- Ensure the primary qbservable source is produced by a valid IQbservableProvider before combining.
- Null-check first (and second) before calling CombineLatest.
- If the first source can be absent, substitute an empty/never qbservable or restructure so a non-null source always exists.
Example fix
// before IQbservable<int> first = null; var combined = first.CombineLatest(second); // after var first = provider.FromNumbers(); var combined = first.CombineLatest(second);
Defensive patterns
Strategy: validation
Validate before calling
if (first is null || second is null) throw new InvalidOperationException("CombineLatest requires non-null first and second sources."); Type guard
static bool IsCombinable<T>(IQbservable<T> q) => q is not null && q.Provider is not null;
Try / catch
try { var combined = first.CombineLatest(second); }
catch (ArgumentNullException ex) when (ex.ParamName == "first") { /* rebuild the primary qbservable */ } Prevention
- Build qbservable sources through providers only; avoid nullable source variables.
- Default optional sources to Observable.Never instead of null.
- Cover stream-construction branches with tests so null producers fail in CI.
When it happens
Trigger: Calling first.CombineLatest(second) where first is a null IQbservable<TFirst>; e.g. a pipeline stage that produced null instead of a qbservable, or passing null as the first argument of the static call.
Common situations: Conditional query construction where the first branch was skipped; mocks in tests returning null; chaining off results of provider.CreateQuery paths that failed silently upstream.
Related errors
- source
- keySelector
- Value cannot be null. (Parameter 'keySelector')
- Value cannot be null. (Parameter 'comparer')
- Value cannot be null. (Parameter 'first')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/6a8155da07ade2d3.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs:35
namespace System.Reactive.Linq
{
public static partial class QbservableEx
{
/// <summary>
/// Merges the specified observable sequences into one observable sequence of tuple values whenever any of the observable sequences produces an element.
/// </summary>
/// <typeparam name="TFirst">The type of the elements in the first source sequence.</typeparam>
/// <typeparam name="TSecond">The type of the elements in the second source sequence.</typeparam>
/// <param name="first">First observable source.</param>
/// <param name="second">Second 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" /> is null.</exception>
public static IQbservable<(TFirst First, TSecond Second)> CombineLatest<TFirst, TSecond>(this IQbservable<TFirst> first, IObservable<TSecond> second)
{
if (first == null)
throw new ArgumentNullException(nameof(first));
if (second == null)
throw new ArgumentNullException(nameof(second));
return first.Provider.CreateQuery<(TFirst First, TSecond Second)>(
Expression.Call(
null,
new Func<IQbservable<TFirst>, IObservable<TSecond>, IQbservable<(TFirst First, TSecond Second)>>(CombineLatest<TFirst, TSecond>).Method,
first.Expression,
GetSourceExpression(second)
)
);
}
/// <summary>
/// Merges the specified observable sequences into one observable sequence of tuple values whenever any of the observable sequences produces an element.
/// </summary>
/// <typeparam name="TFirst">The type of the elements in the first source sequence.</typeparam>
/// <typeparam name="TSecond">The type of the elements in the second source sequence.</typeparam>View on GitHub (pinned to 94b5d5ab91)