dotnet/reactive · error · ArgumentNullException
ArgumentNullException
Error message
ArgumentNullException
What it means
The async-predicate Where overload (Func<TSource, ValueTask<bool>>) validates inputs eagerly and throws ArgumentNullException with param name 'source' when the source IAsyncObservable<TSource> is null. Note: with the parameterless ArgumentNullException constructor, the exception message does not name the parameter — the param name comes from the throw site.
Solutions
- Ensure the async source-producing method returns a non-null observable, not null.
- Null-check the awaited source before composing the query.
- Replace null returns in factories with AsyncObservable.Empty<TSource>().
Example fix
// before var source = await GetSourceAsync(); // returns null var filtered = source.Where(async x => await CheckAsync(x)); // after var source = await GetSourceAsync() ?? AsyncObservable.Empty<int>(); var filtered = source.Where(async x => await CheckAsync(x));
Defensive patterns
Strategy: validation
Validate before calling
var source = await GetSourceAsync();
if (source == null)
source = AsyncObservable.Empty<TSource>(); Type guard
bool HasSource<T>(IAsyncObservable<T> source) => source is not null;
Try / catch
try
{
var filtered = source.Where(async x => await CheckAsync(x));
}
catch (ArgumentNullException ex) when (ex.ParamName == "source")
{
// log the null source and use an empty observable
} Prevention
- Ensure async factories await a non-null result before composition.
- Return AsyncObservable.Empty<T>() rather than null from async producers.
- Assert non-null after awaits in debug builds (Debug.Assert(source != null)).
When it happens
Trigger: Chaining .Where(asyncPredicate) on a null IAsyncObservable<TSource>; e.g. a null returned by a preceding custom async operator or an uninitialized variable.
Common situations: Async factory methods (Task<IAsyncObservable<T>>) whose await result was null; cached lookups missing; code paths composing queries before the source assignment completes.
Related errors
- ArgumentNullException(nameof(source))
- ArgumentNullException(nameof(predicate))
- ArgumentNullException(nameof(plans))
- Value cannot be null. (Parameter 'subscribeAsync')
- Value cannot be null. (Parameter 'observer')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/d2b349a94ec1855b.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/Where.cs:27
public partial class AsyncObservable
{
public static IAsyncObservable<TSource> Where<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<TSource>.From(
source,
predicate,
static (source, predicate, observer) => source.SubscribeSafeAsync(AsyncObserver.Where(observer, predicate)));
}
public static IAsyncObservable<TSource> Where<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<TSource>.From(
source,
predicate,
static (source, predicate, observer) => source.SubscribeSafeAsync(AsyncObserver.Where(observer, predicate)));
}
public static IAsyncObservable<TSource> Where<TSource>(this IAsyncObservable<TSource> source, Func<TSource, int, bool> predicate)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (predicate == null)
throw new ArgumentNullException(nameof(predicate));
return CreateAsyncObservable<TSource>.From(
source,View on GitHub (pinned to 94b5d5ab91)