dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'source5')

Error message

Value cannot be null. (Parameter 'source5')

What it means

System.ArgumentNullException thrown by Observable.Zip's 5-source overload when the fifth source sequence (source5) is null. This is the last source checked before resultSelector in the 5-source Zip; the exception is raised eagerly at call time.

Solutions

  1. Ensure source5 is a valid IObservable<T>; substitute Observable.Empty<T5>() if the stream is optional.
  2. Register/initialize the fifth stream's producer so it no longer returns null.
  3. Coalesce at the call site: source5 ?? Observable.Empty<T5>().

Example fix

// before
var z = Observable.Zip(s1, s2, s3, s4, auditStream, sel); // auditStream not wired, null
// after
var z2 = Observable.Zip(s1, s2, s3, s4, auditStream ?? Observable.Empty<AuditEvent>(), sel);
Defensive patterns

Strategy: validation

Validate before calling

if (source5 is null) throw new InvalidOperationException("source5 stream was not initialized");

Type guard

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

Try / catch

try { var z = Observable.Zip(s1, s2, s3, s4, source5, sel); }
catch (ArgumentNullException ex) when (ex.ParamName == "source5") { log.Error("Fifth stream was null"); }

Prevention

When it happens

Trigger: Calling Observable.Zip(source1, source2, source3, source4, null, resultSelector) with a null fifth IObservable<T> argument.

Common situations: Five-way merges where the fifth stream is optional (e.g. an audit or metrics stream) and was not wired; nullable fields for peripheral streams; DI registrations missing for the fifth dependency.

Related errors


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

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Multiple.Zip.cs:135

            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.Zip(source1, source2, source3, source4, source5, resultSelector);
        }

        /// <summary>
        /// Merges the specified observable sequences into one observable sequence by using the selector function whenever all of the observable sequences have produced an element at a corresponding index.
        /// </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)