dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'tenth')

Error message

Value cannot be null. (Parameter 'tenth')

What it means

System.Reactive's public Observable.CombineLatest overload taking ten source sequences eagerly validates each argument and throws ArgumentNullException when any is null. Rx operators do not accept null sources; validation happens synchronously at call time before any subscription. Here the 'tenth' argument was null.

Solutions

  1. Assign a real observable to the tenth argument before calling CombineLatest.
  2. If the source may be absent, substitute Observable.Empty<T>() (or a default sequence) instead of null.
  3. Check the code path producing the tenth sequence (factory, cache, config) and fix why it returns null.
  4. Wrap the call in ArgumentNullException handling only at top-level boundaries to surface a clear diagnostic.

Example fix

// before
IObservable<int> tenth = sources.TryGetValue("tenth", out var s) ? s : null;
var z = Observable.CombineLatest(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth);
// after
IObservable<int> tenth = sources.TryGetValue("tenth", out var s) ? s : Observable.Empty<int>();
var z = Observable.CombineLatest(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth);
Defensive patterns

Strategy: validation

Validate before calling

if (tenth == null) throw new InvalidOperationException("CombineLatest: 'tenth' source is null — supply a real observable or Observable.Empty<int>()");

Type guard

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

Try / catch

try { return Observable.CombineLatest(a,b,c,d,e,f,g,h,i,j); }
catch (ArgumentNullException ex) when (ex.ParamName == "tenth") { log.Error("tenth source was null"); return Observable.Empty<(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10)>(); }

Prevention

When it happens

Trigger: Calling Observable.CombineLatest(first..tenth) where the tenth IObservable<T> argument is null, e.g. a variable that was never assigned, a dictionary/lookup miss returning null, or a factory method that returned null.

Common situations: Building CombineLatest chains from conditional sources (if/else that leaves a variable null), mock setups returning null, nullable fields not yet initialized, or deserialized configuration where a source was expected but absent.

Related errors


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

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Multiple.CombineLatest.cs:1510

                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));
            if (tenth == null)
                throw new ArgumentNullException(nameof(tenth));

            return s_impl.CombineLatest(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth);
        }

        /// <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>
        /// <typeparam name="TThird">The type of the elements in the third source sequence.</typeparam>
        /// <typeparam name="TFourth">The type of the elements in the fourth source sequence.</typeparam>
        /// <typeparam name="TFifth">The type of the elements in the fifth source sequence.</typeparam>
        /// <typeparam name="TSixth">The type of the elements in the sixth source sequence.</typeparam>
        /// <typeparam name="TSeventh">The type of the elements in the seventh source sequence.</typeparam>
        /// <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>
        /// <typeparam name="TTenth">The type of the elements in the tenth source sequence.</typeparam>
        /// <typeparam name="TEleventh">The type of the elements in the eleventh source sequence.</typeparam>

View on GitHub (pinned to 94b5d5ab91)