dotnet/reactive · error · ArgumentNullException
source
Error message
source
What it means
IsEmpty validates the source observable at operator-creation time; without a source there is nothing whose emptiness can be checked. Standard ArgumentNullException guard in the LINQ operator. Fix: pass a non-null IAsyncObservable<TSource>.
Solutions
- Ensure the source IAsyncObservable<TSource> is non-null before calling IsEmpty; fall back to AsyncObservable.Empty<TSource>().
- Trace the producer of the null observable and make it return an empty observable instead of null.
- Add a null guard before the operator chain.
Example fix
// before var empty = GetSource()?.IsEmpty(); // NullReference or ANE path // after var src = GetSource() ?? AsyncObservable.Empty<int>(); var empty = src.IsEmpty();
Defensive patterns
Strategy: validation
Validate before calling
if (source is null) throw new ArgumentException("source must be non-null");
// or: source ??= AsyncObservable.Empty<TSource>(); Type guard
static bool HasSource<TSource>(IAsyncObservable<TSource> s) => s is not null;
Try / catch
try { var isEmpty = src.IsEmpty(); }
catch (ArgumentNullException ex) when (ex.ParamName == "source") { /* substitute Empty<TSource>() */ } Prevention
- Make stream-producing APIs return empty streams instead of null
- Apply ?? Empty<T>() before operator chains
- Use nullable reference type annotations on stream-producing methods
When it happens
Trigger: Calling source.IsEmpty() on a null receiver or AsyncObservable.IsEmpty(null), typically from a nullable observable obtained via lookup, config, or a null-returning method.
Common situations: Fluent chains built on results of methods that can return null (repository/cache lookups), especially when combining multiple query results.
Related errors
- source
- left
- null (Parameter 'scheduler')
- null (Parameter 'values')
- Value cannot be null. (Parameter 'observer')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/abcbc52d94c4a493.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/IsEmpty.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<bool> IsEmpty<TSource>(this IAsyncObservable<TSource> source)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
return Create<TSource, bool>(source, static (source, observer) => source.SubscribeSafeAsync(AsyncObserver.IsEmpty<TSource>(observer)));
}
}
public partial class AsyncObserver
{
public static IAsyncObserver<TSource> IsEmpty<TSource>(IAsyncObserver<bool> observer)
{
if (observer == null)
throw new ArgumentNullException(nameof(observer));
return Any<TSource>(Select<bool, bool>(observer, b => !b));
}
}
}
View on GitHub (pinned to 94b5d5ab91)