dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'predicate')
Error message
Value cannot be null. (Parameter 'predicate')
What it means
The synchronous All operator throws ArgumentNullException when the predicate Func<TSource, bool> is null. The predicate decides whether the sequence 'matches all'; the library rejects a null predicate at construction so failures surface immediately with the parameter name.
Solutions
- Pass a concrete predicate lambda, e.g. x => x > 0.
- Supply a sensible default: predicate ?? (_ => true).
- Guard optional predicates at the caller: if (predicate == null) throw new ArgumentNullException(nameof(predicate));
Example fix
// before var ok = source.All(null); // after var ok = source.All(x => x > 0);
Defensive patterns
Strategy: validation
Validate before calling
if (predicate == null) throw new ArgumentNullException(nameof(predicate)); // or: predicate ??= (_ => true);
Type guard
static bool IsValidPredicate<T>(Func<T, bool> p) => p != null;
Try / catch
try { var q = source.All(predicate); }
catch (ArgumentNullException ex) when (ex.ParamName == "predicate") { /* use default predicate */ } Prevention
- Give optional predicate parameters non-null defaults (_ => true or _ => false).
- Avoid conditional lambda construction that can yield null.
- Pass lambdas directly at the call site instead of through nullable variables.
When it happens
Trigger: Calling source.All(null) or All(source, (Func<TSource, bool>)null), often when the predicate is stored in a variable, passed as an optional parameter, or built conditionally.
Common situations: Optional predicate parameters defaulted to null, predicate factories returning null on config misses, or refactors removing the lambda while keeping the call.
Related errors
- Value cannot be null. (Parameter 'source')
- Value cannot be null. (Parameter 'predicate')
- Value cannot be null. (Parameter 'condition')
- predicate
- Value cannot be null. (Parameter 'predicate')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/4cab330cf207ce3e.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/All.cs:16
// 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.
using System.Threading.Tasks;
namespace System.Reactive.Linq
{
public partial class AsyncObservable
{
public static IAsyncObservable<bool> All<TSource>(this IAsyncObservable<TSource> source, Func<TSource, bool> predicate)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (predicate == null)
throw new ArgumentNullException(nameof(predicate));
return CreateAsyncObservable<bool>.From(
source,
predicate,
static (source, predicate, observer) => source.SubscribeSafeAsync(AsyncObserver.All(observer, predicate)));
}
public static IAsyncObservable<bool> All<TSource>(this IAsyncObservable<TSource> source, Func<TSource, ValueTask<bool>> predicate)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (predicate == null)
throw new ArgumentNullException(nameof(predicate));
return CreateAsyncObservable<bool>.From(
source,
predicate,
static (source, predicate, observer) => source.SubscribeSafeAsync(AsyncObserver.All(observer, predicate)));View on GitHub (pinned to 94b5d5ab91)