dotnet/reactive · error · ArgumentNullException

predicate

Error message

predicate

What it means

Thrown by AsyncObserver.Single(observer, Func<TSource,ValueTask<bool>>) when the async predicate argument is null. The parameter name reported is simply 'predicate'. Like the other overloads, the guard fires before the composed observer is built.

Solutions

  1. Pass a valid ValueTask<bool>-returning predicate, or cast a lambda to the desired overload
  2. Use the sync predicate overload when no async work is required
  3. Use the predicateless overload if no filter is intended

Example fix

// before
var obs = AsyncObserver.Single<int>(downstream, (Func<int, ValueTask<bool>>)null);
// after
var obs = AsyncObserver.Single<int>(downstream, async x => await CheckAsync(x));
Defensive patterns

Strategy: validation

Validate before calling

if (asyncPredicate is null) throw new ArgumentNullException(nameof(predicate));

Type guard

static bool IsValidAsyncPredicate<T>(Func<T, ValueTask<bool>>? p) => p is not null;

Try / catch

try { var o = AsyncObserver.Single<T>(observer, asyncPred); }
catch (ArgumentNullException ex) when (ex.ParamName == "predicate") { /* supply async predicate */ }

Prevention

When it happens

Trigger: Calling AsyncObserver.Single(observer, (Func<TSource,ValueTask<bool>>)null) with a null async predicate.

Common situations: Overload-resolution confusion where a null literal bound to the ValueTask overload; predicates not yet initialized in dynamic pipelines.

Related errors


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

Appendix: source

Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/Single.cs:103

            );
        }

        public static IAsyncObserver<TSource> Single<TSource>(IAsyncObserver<TSource> observer, Func<TSource, bool> predicate)
        {
            if (observer == null)
                throw new ArgumentNullException(nameof(observer));
            if (predicate == null)
                throw new ArgumentNullException(nameof(predicate));

            return Where(Single(observer), predicate);
        }

        public static IAsyncObserver<TSource> Single<TSource>(IAsyncObserver<TSource> observer, Func<TSource, ValueTask<bool>> predicate)
        {
            if (observer == null)
                throw new ArgumentNullException(nameof(observer));
            if (predicate == null)
                throw new ArgumentNullException(nameof(predicate));

            return Where(Single(observer), predicate);
        }
    }
}

View on GitHub (pinned to 94b5d5ab91)