dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'source')
Error message
Value cannot be null. (Parameter 'source')
What it means
Materialize converts an async observable into a sequence of Notification<TSource> values; it validates its source at Materialize.cs:12 before wiring the Subscription. A null source cannot be subscribed to, so ArgumentNullException is thrown eagerly at operator construction.
Solutions
- Ensure the observable passed to Materialize is non-null.
- Substitute an empty observable when the source is legitimately absent: source ?? AsyncObservable.Empty<T>().
- Check upstream factory/registry code that produced a null observable.
Example fix
// before var notifications = AsyncObservable.Materialize(maybeSource); // null // after var notifications = AsyncObservable.Materialize(maybeSource ?? AsyncObservable.Empty<T>());
Defensive patterns
Strategy: validation
Validate before calling
if (source is null) throw new InvalidOperationException("Materialize requires a non-null source");
var notifications = source.Materialize(); Type guard
static bool CanMaterialize<T>(IAsyncObservable<T>? s) => s is not null;
Try / catch
try { var notifications = source.Materialize(); }
catch (ArgumentNullException ex) when (ex.ParamName == "source") { var notifications = Array.Empty<Notification<T>>(); } Prevention
- Resolve streams from registries with non-null guarantees or coalesce to AsyncObservable.Empty<T>().
- Enable nullable reference types to catch null sources statically.
- Wrap stream-lookup helpers so they never return null observables.
When it happens
Trigger: Calling AsyncObservable.Materialize<TSource>(null) — null IAsyncObservable<TSource> passed to the operator at Materialize.cs:12.
Common situations: Tracing/logging wrappers that materialize a stream obtained from a resolver or registry which returned null; unit tests passing null to check error behavior.
Related errors
- conversion
- addHandler
- Value cannot be null. (Parameter 'predicate')
- Value cannot be null. (Parameter 'observer')
- Value cannot be null. (Parameter 'onCompletedAsync')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/a4d1de3b8f8b25ba.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/Materialize.cs:12
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT License.
// See the LICENSE file in the project root for more information.
namespace System.Reactive.Linq
{
public partial class AsyncObservable
{
public static IAsyncObservable<Notification<TSource>> Materialize<TSource>(this IAsyncObservable<TSource> source)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
return Create<TSource, Notification<TSource>>(source, static (source, observer) => source.SubscribeSafeAsync(AsyncObserver.Materialize(observer)));
}
}
public partial class AsyncObserver
{
public static IAsyncObserver<TSource> Materialize<TSource>(IAsyncObserver<Notification<TSource>> observer)
{
if (observer == null)
throw new ArgumentNullException(nameof(observer));
return Create<TSource>(
x => observer.OnNextAsync(Notification.CreateOnNext(x)),
async ex =>
{
await observer.OnNextAsync(Notification.CreateOnError<TSource>(ex)).ConfigureAwait(false);
await observer.OnCompletedAsync().ConfigureAwait(false);View on GitHub (pinned to 94b5d5ab91)