dotnet/reactive · error · ArgumentNullException
source
Error message
source
What it means
The ListObservable constructor subscribes to the given source and throws ArgumentNullException when 'source' is null, since the observable to record is required to build the internal results list and subject.
Solutions
- Pass a valid IObservable<T> instance (use Observable.Never<T>() or Empty as a placeholder if needed)
- Null-check the source before constructing ListObservable
- Fix the factory/dependency that returned null
Example fix
// before var obs = new ListObservable<int>(maybeSource); // may be null // after if (maybeSource == null) maybeSource = Observable.Empty<int>(); var obs = new ListObservable<int>(maybeSource);
Defensive patterns
Strategy: validation
Validate before calling
if (source == null) throw new ArgumentNullException(nameof(source)); var obs = new ListObservable<T>(source);
Type guard
static bool IsObservable<T>(IObservable<T> s) => s != null;
Try / catch
try { var obs = new ListObservable<int>(source); } catch (ArgumentNullException) { /* null source */ } Prevention
- Null-check observables before constructing recording wrappers
- Default to Observable.Never<T>() when a real source is unavailable
- Ensure stream factories never return null
When it happens
Trigger: Constructing new ListObservable<T>(null), e.g. passing an uninitialized observable field or a factory result that was null.
Common situations: Test harness code capturing notifications from a stream whose setup failed silently; DI/wiring produced null for the source observable.
Related errors
- Value cannot be null. (Parameter 'comparer')
- observer
- Value cannot be null. (Parameter 'onNextAsync')
- Value cannot be null. (Parameter 'onErrorAsync')
- Value cannot be null. (Parameter 'onCompletedAsync')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/561f0305da47ca4a.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/ListObservable.cs:35
/// </summary>
/// <typeparam name="T">The type of elements received from the source sequence.</typeparam>
[Experimental]
public class ListObservable<T> : IList<T>, IObservable<object>
{
private readonly IDisposable _subscription;
private readonly AsyncSubject<object> _subject = new();
private readonly List<T> _results = [];
/// <summary>
/// Constructs an object that retains the values of source and signals the end of the sequence.
/// </summary>
/// <param name="source">The observable sequence whose elements will be retained in the list.</param>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <c>null</c>.</exception>
public ListObservable(IObservable<T> source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
_subscription = source.Subscribe(_results.Add, _subject.OnError, _subject.OnCompleted);
}
private void Wait()
{
_subject.DefaultIfEmpty().Wait();
}
/// <summary>
/// Returns the last value of the observable sequence.
/// </summary>
public T Value
{
get
{
Wait();View on GitHub (pinned to 94b5d5ab91)