dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'second')
Error message
Value cannot be null. (Parameter 'second')
What it means
The nine-source tuple CombineLatest overload throws ArgumentNullException for parameter 'second' when the second observable source is null. Like all Rx public operators, it validates arguments eagerly at composition time so that broken pipelines are reported at the exact call site. The doc comment guarantees that none of first..ninth may be null.
Solutions
- Supply a non-null IObservable<TSecond> for the second argument
- Fall back to Observable.Empty<TSecond>() or Observable.Never<TSecond>() for optional streams
- Trace and fix the null-producing initializer of the second stream
- Assert non-nullness of all streams at pipeline construction in debug builds
Example fix
// before var combined = first.CombineLatest(second, third, ...); // second == null // after var combined = first.CombineLatest(second ?? Observable.Empty<TSecond>(), third, ...);
Defensive patterns
Strategy: validation
Validate before calling
if (second == null) throw new InvalidOperationException("second stream must be initialized before CombineLatest"); Type guard
bool IsNonNull<T>(IObservable<T> s) => s is not null;
Try / catch
try { var combined = first.CombineLatest(second, third, /* ... */); } catch (ArgumentNullException ex) when (ex.ParamName == "second") { /* substitute default stream */ } Prevention
- Initialize secondary streams (settings, polling) eagerly in startup code
- Return Observable.Never<T>() rather than null for not-yet-active streams
- Avoid copy-paste editing of long CombineLatest argument lists; use named locals
- Enable nullable reference types for compile-time detection
When it happens
Trigger: Calling the 9-argument CombineLatest with a null IObservable<TSecond> in the second position.
Common situations: A secondary stream (e.g. a settings or polling stream) that failed to initialize; event aggregators returning null for unsubscribed channels; copy-pasted combine chains where one argument was left as null during editing.
Related errors
- keySelector
- Value cannot be null. (Parameter 'keySelector')
- Value cannot be null. (Parameter 'comparer')
- Value cannot be null. (Parameter 'first')
- Value cannot be null. (Parameter 'third')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/b875d1abeb89c979.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Multiple.CombineLatest.cs:1445
/// <typeparam name="TEighth">The type of the elements in the eighth source sequence.</typeparam>
/// <typeparam name="TNinth">The type of the elements in the ninth 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>
/// <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"/> is null.</exception>
public static IObservable<(TFirst First, TSecond Second, TThird Third, TFourth Fourth, TFifth Fifth, TSixth Sixth, TSeventh Seventh, TEighth Eighth, TNinth Ninth)> CombineLatest<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TEighth, TNinth>(this IObservable<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)
{
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));
return s_impl.CombineLatest(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth);
}
View on GitHub (pinned to 94b5d5ab91)