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

  1. Ensure the source IAsyncObservable<TSource> is non-null before chaining; use AsyncObservable.Empty<TSource>() as a substitute.
  2. Find the producer of the null observable (return null path in a factory/repository) and make it return an empty observable instead.
  3. 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

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


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)