dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'source5')

Error message

Value cannot be null. (Parameter 'source5')

What it means

Observable.CombineLatest (5-source overload) throws ArgumentNullException when the resultSelector delegate is null. The selector combines the latest value of each of the five sources into a result; Rx checks it eagerly at call time with parameter name 'resultSelector'.

Solutions

  1. Pass a concrete non-null Func<TSource1,...,TSource5,TResult> as the last argument
  2. If the projection is optional, supply a default projection (e.g. tuple or array of latest values) instead of null
  3. Check the code path that builds the selector and make it return a fallback delegate rather than null
  4. Validate the selector before composing: if (resultSelector == null) throw new InvalidOperationException("No projection configured")

Example fix

// before
Func<int, int, int, int, int, string> selector = _config.Mode == "sum" ? Sum : null;
var combined = Observable.CombineLatest(a, b, c, d, e, selector); // throws in default mode

// after
Func<int, int, int, int, int, string> selector = _config.Mode == "sum" ? Sum : Default;
var combined = Observable.CombineLatest(a, b, c, d, e, selector);
Defensive patterns

Strategy: validation

Validate before calling

if (resultSelector is null) throw new ArgumentNullException(nameof(resultSelector));
var combined = Observable.CombineLatest(source1, source2, source3, source4, source5, resultSelector);

Type guard

static bool IsUsable<T1,T2,T3,T4,T5,TResult>(Func<T1,T2,T3,T4,T5,TResult>? f) => f is not null;

Try / catch

try
{
    combined = Observable.CombineLatest(s1, s2, s3, s4, s5, resultSelector);
}
catch (ArgumentNullException ex) when (ex.ParamName == "resultSelector")
{
    resultSelector = DefaultProjection;
    combined = Observable.CombineLatest(s1, s2, s3, s4, s5, resultSelector);
}

Prevention

When it happens

Trigger: Calling Observable.CombineLatest(s1, s2, s3, s4, s5, null) — e.g. the selector was computed at runtime, returned null from a factory, or a conditional expression like (useA ? selA : selB) yielded null.

Common situations: Building query DSLs where the projection is optional; reflection-based or config-driven composition where the selector method name failed to resolve to a delegate; nullable Func fields not yet initialized.

Related errors


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

Appendix: source

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

            if (source2 == null)
            {
                throw new ArgumentNullException(nameof(source2));
            }

            if (source3 == null)
            {
                throw new ArgumentNullException(nameof(source3));
            }

            if (source4 == null)
            {
                throw new ArgumentNullException(nameof(source4));
            }

            if (source5 == null)
            {
                throw new ArgumentNullException(nameof(source5));
            }

            if (resultSelector == null)
            {
                throw new ArgumentNullException(nameof(resultSelector));
            }

            return s_impl.CombineLatest(source1, source2, source3, source4, source5, resultSelector);
        }

        /// <summary>
        /// Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.
        /// </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="TSource3">The type of the elements in the third source sequence.</typeparam>
        /// <typeparam name="TSource4">The type of the elements in the fourth source sequence.</typeparam>
        /// <typeparam name="TSource5">The type of the elements in the fifth source sequence.</typeparam>

View on GitHub (pinned to 94b5d5ab91)