dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'source')
Error message
Value cannot be null. (Parameter 'source')
What it means
The synchronous All operator (IAsyncObservable<bool> All<TSource>(source, Func<TSource, bool> predicate)) throws ArgumentNullException when the source observable is null. AsyncRx.NET validates operator arguments eagerly so that a null source fails at query construction instead of at subscription time.
Solutions
- Ensure the source is created before the query: var src = AsyncObservable.FromArray(items); then src.All(x => ...).
- Null-check or null-coalesce the source before composing: source ?? AsyncObservable.Empty<T>().
- Fix the upstream producer so it never returns null (throw its own descriptive error instead).
Example fix
// before
IAsyncObservable<int> source = null;
var anyFail = source.All(x => x > 0); // throws
// after
var source = AsyncObservable.FromArray(new[] { 1, 2, 3 });
var anyFail = source.All(x => x > 0); Defensive patterns
Strategy: validation
Validate before calling
if (source == null) throw new ArgumentNullException(nameof(source)); // or: var safe = source ?? AsyncObservable.Empty<TSource>();
Type guard
static bool HasSource<TSource>(IAsyncObservable<TSource> s) => s is not null;
Try / catch
try { var q = source.All(x => x > 0); }
catch (ArgumentNullException ex) when (ex.ParamName == "source") { /* initialize source and retry composition */ } Prevention
- Initialize observables eagerly (constructor or field initializer), not lazily.
- Never let factory methods return null observables; return Empty instead.
- Compose query pipelines immediately after source creation.
When it happens
Trigger: Calling source.All(predicate) via the extension method with source == null, or AsyncObservable.All(null, predicate) directly — e.g. a field holding the observable that was never assigned.
Common situations: Chained queries where an earlier factory returned null, lazy-initialized observables used before assignment, or null propagating from a configuration-provided source.
Related errors
- source
- Value cannot be null. (Parameter 'source')
- Value cannot be null. (Parameter 'disposable1')
- Value cannot be null. (Parameter 'disposable2')
- Value cannot be null. (Parameter 'onNextAsync')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/7b88efe0cec71fe9.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/All.cs:14
// 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.
using System.Threading.Tasks;
namespace System.Reactive.Linq
{
public partial class AsyncObservable
{
public static IAsyncObservable<bool> All<TSource>(this IAsyncObservable<TSource> source, Func<TSource, bool> predicate)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (predicate == null)
throw new ArgumentNullException(nameof(predicate));
return CreateAsyncObservable<bool>.From(
source,
predicate,
static (source, predicate, observer) => source.SubscribeSafeAsync(AsyncObserver.All(observer, predicate)));
}
public static IAsyncObservable<bool> All<TSource>(this IAsyncObservable<TSource> source, Func<TSource, ValueTask<bool>> predicate)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (predicate == null)
throw new ArgumentNullException(nameof(predicate));
return CreateAsyncObservable<bool>.From(
source,View on GitHub (pinned to 94b5d5ab91)