dotnet/reactive · error · ArgumentNullException

observer

Error message

observer

What it means

AsyncObserver.IgnoreElements(observer) throws ArgumentNullException with paramName "observer" when the downstream IAsyncObserver<TSource> is null. This is the observer-level API used when building custom observers; it composes Where(observer, _ => false) and must receive a valid downstream observer.

Solutions

  1. Pass the actual downstream IAsyncObserver<TSource> received in SubscribeSafeAsync/SubscribeAsync to AsyncObserver.IgnoreElements.
  2. Fix the custom observable/observer implementation that stores or forwards a null observer.
  3. Add an ArgumentNullException guard in your own operator so the failure is attributed correctly.

Example fix

// before
public IAsyncDisposable SubscribeAsync(IAsyncObserver<int> observer)
    => AsyncObserver.IgnoreElements(_observer); // _observer not initialized
// after
public IAsyncDisposable SubscribeAsync(IAsyncObserver<int> observer)
    => source.SubscribeSafeAsync(AsyncObserver.IgnoreElements(observer));
Defensive patterns

Strategy: validation

Validate before calling

if (observer is null) throw new ArgumentNullException(nameof(observer));
// before calling AsyncObserver.IgnoreElements(observer)

Type guard

static bool HasObserver<TSource>(IAsyncObserver<TSource> o) => o is not null;

Try / catch

try { var o = AsyncObserver.IgnoreElements(observer); }
catch (ArgumentNullException ex) when (ex.ParamName == "observer") { /* fix observer wiring */ }

Prevention

When it happens

Trigger: Calling AsyncObserver.IgnoreElements(null) while hand-rolling a custom observer pipeline, or passing a null observer from a custom SubscribeAsync implementation.

Common situations: Writing a custom operator where the downstream observer comes from a nullable constructor parameter or an unassigned field in a custom IAsyncObservable implementation.

Related errors


AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15). Data as JSON: /api/errors/fe9128502416d1e6. Report an issue: GitHub.

Appendix: source

Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/IgnoreElements.cs:23

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)