{"record":{"id":"4cab330cf207ce3e","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-predicate","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'predicate')","messagePattern":"Value cannot be null\\. \\(Parameter 'predicate'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/All.cs","lineNumber":16,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<bool> All<TSource>(this IAsyncObservable<TSource> source, Func<TSource, bool> predicate)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (predicate == null)\n                throw new ArgumentNullException(nameof(predicate));\n\n            return CreateAsyncObservable<bool>.From(\n                source,\n                predicate,\n                static (source, predicate, observer) => source.SubscribeSafeAsync(AsyncObserver.All(observer, predicate)));\n        }\n\n        public static IAsyncObservable<bool> All<TSource>(this IAsyncObservable<TSource> source, Func<TSource, ValueTask<bool>> predicate)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (predicate == null)\n                throw new ArgumentNullException(nameof(predicate));\n\n            return CreateAsyncObservable<bool>.From(\n                source,\n                predicate,\n                static (source, predicate, observer) => source.SubscribeSafeAsync(AsyncObserver.All(observer, predicate)));","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/All.cs#L1-L34","documentation":"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.","triggerScenarios":"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.","commonSituations":"Optional predicate parameters defaulted to null, predicate factories returning null on config misses, or refactors removing the lambda while keeping the call.","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));"],"exampleFix":"// before\nvar ok = source.All(null);\n// after\nvar ok = source.All(x => x > 0);","handlingStrategy":"validation","validationCode":"if (predicate == null) throw new ArgumentNullException(nameof(predicate));\n// or: predicate ??= (_ => true);","typeGuard":"static bool IsValidPredicate<T>(Func<T, bool> p) => p != null;","tryCatchPattern":"try { var q = source.All(predicate); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"predicate\") { /* use default predicate */ }","preventionTips":["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."],"tags":["argument-null","predicate","all"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}