dotnet/reactive · error · ArgumentNullException
source
Error message
source
What it means
IgnoreElements(source) throws ArgumentNullException with paramName "source" when the source observable is null. This is a standard eager guard in AsyncRx operators, ensuring misuse is caught at the call site rather than during async subscription.
Solutions
- Ensure the source IAsyncObservable<TSource> is non-null before chaining; use AsyncObservable.Empty<TSource>() as a substitute.
- Find the producer of the null observable (return null path in a factory/repository) and make it return an empty observable instead.
- Add a null check or ?? fallback before calling IgnoreElements.
Example fix
// before IObservable<int> src = GetSource(); // null var ignored = src.IgnoreElements(); // after IObservable<int> src = GetSource() ?? AsyncObservable.Empty<int>(); var ignored = src.IgnoreElements();
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 ignored = src.IgnoreElements(); }
catch (ArgumentNullException ex) when (ex.ParamName == "source") { /* repair or substitute source */ } Prevention
- Never let producer methods return null observables
- Use ?? AsyncObservable.Empty<T>() in fluent chains
- Enable nullable reference types to catch null flows at compile time
When it happens
Trigger: Calling source.IgnoreElements() via a null extension-receiver, or AsyncObservable.IgnoreElements(null), e.g. when the observable came from a nullable field or failed lookup.
Common situations: Chaining operators on a value that is null because an earlier pipeline stage returned null (e.g. a cache or service locator miss), or a null-returning factory used in fluent chains.
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/28a43f54fce81672.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/IgnoreElements.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<TSource> IgnoreElements<TSource>(this IAsyncObservable<TSource> source)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
return Create(source, static (source, observer) => source.SubscribeSafeAsync(AsyncObserver.IgnoreElements(observer)));
}
}
public partial class AsyncObserver
{
public static IAsyncObserver<TSource> IgnoreElements<TSource>(IAsyncObserver<TSource> observer)
{
if (observer == null)
throw new ArgumentNullException(nameof(observer));
return Where(observer, _ => false);
}
}
}
View on GitHub (pinned to 94b5d5ab91)