dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'source4')

Error message

Value cannot be null. (Parameter 'source4')

What it means

The 7-source Zip operator overload (async Func selector form preceding the non-selector overload at line 533) validates all arguments up front. A null was passed as the 4th source observable, so the library eagerly throws ArgumentNullException('source4') before any subscription happens. This is fail-fast argument validation: zipping requires every input sequence to be non-null.

Solutions

  1. Pass a real IAsyncObservable for source4; if the input is genuinely optional, substitute AsyncObservable.Empty<T4>() so the zip completes immediately.
  2. Guard before the call: check each source for null (throw or default) so the failure is caught at the construction site with a clear message.
  3. If the 4th source may be absent, collapse to a lower-arity Zip overload (e.g. the 3-source one) instead of passing null.

Example fix

// before
var merged = AsyncObservable.Zip(s1, s2, s3, maybeFourth, s5, s6, s7);
// after
var merged = AsyncObservable.Zip(s1, s2, s3, maybeFourth ?? AsyncObservable.Empty<T4>(), s5, s6, s7);
Defensive patterns

Strategy: validation

Validate before calling

if (source4 == null) throw new InvalidOperationException("source4 must be provided before zipping");

Type guard

bool IsValidZipInput<T>(IAsyncObservable<T> s) => s is not null;

Try / catch

try
{
    var zipped = AsyncObservable.Zip(s1, s2, s3, s4, s5, s6, s7);
}
catch (ArgumentNullException ex) when (ex.ParamName == "source4")
{
    logger.LogError(ex, "4th zip source was null");
}

Prevention

When it happens

Trigger: Calling AsyncObservable.Zip(source1, source2, source3, null, source5, source6, source7) or the analogous 7-ary overload with a null fourth IAsyncObservable argument.

Common situations: A source observable variable that results from a conditional lookup or optional chain is null at call time; refactoring reduced a 7-way zip to fewer inputs but the null placeholder was left in position 4; a factory method returning the 4th stream returned null on some code path.

Related errors


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

Appendix: source

Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/Zip.Generated.cs:500

                var sub6 = source6.SubscribeSafeAsync(observer6).AsTask().ContinueWith(disposable => d.AddAsync(disposable.Result).AsTask()).Unwrap();
                var sub7 = source7.SubscribeSafeAsync(observer7).AsTask().ContinueWith(disposable => d.AddAsync(disposable.Result).AsTask()).Unwrap();

                await Task.WhenAll(sub1, sub2, sub3, sub4, sub5, sub6, sub7).ConfigureAwait(false);

                return d;
            });
        }

        public static IAsyncObservable<TResult> Zip<T1, T2, T3, T4, T5, T6, T7, TResult>(this IAsyncObservable<T1> source1, IAsyncObservable<T2> source2, IAsyncObservable<T3> source3, IAsyncObservable<T4> source4, IAsyncObservable<T5> source5, IAsyncObservable<T6> source6, IAsyncObservable<T7> source7, Func<T1, T2, T3, T4, T5, T6, T7, TResult> selector)
        {
            if (source1 == null)
                throw new ArgumentNullException(nameof(source1));
            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 (source6 == null)
                throw new ArgumentNullException(nameof(source6));
            if (source7 == null)
                throw new ArgumentNullException(nameof(source7));
            if (selector == null)
                throw new ArgumentNullException(nameof(selector));

            return Create<TResult>(async observer =>
            {
                var d = new CompositeAsyncDisposable();

                var (observer1, observer2, observer3, observer4, observer5, observer6, observer7) = AsyncObserver.Zip(observer, selector);

                var sub1 = source1.SubscribeSafeAsync(observer1).AsTask().ContinueWith(disposable => d.AddAsync(disposable.Result).AsTask()).Unwrap();
                var sub2 = source2.SubscribeSafeAsync(observer2).AsTask().ContinueWith(disposable => d.AddAsync(disposable.Result).AsTask()).Unwrap();
                var sub3 = source3.SubscribeSafeAsync(observer3).AsTask().ContinueWith(disposable => d.AddAsync(disposable.Result).AsTask()).Unwrap();

View on GitHub (pinned to 94b5d5ab91)