{"record":{"id":"3d7f4f9007f53cfa","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-predicate-observable","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":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Aggregates.cs","lineNumber":123,"sourceCode":"        /// <summary>\n        /// Determines whether all elements of an observable sequence satisfy a condition.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">An observable sequence whose elements to apply the predicate to.</param>\n        /// <param name=\"predicate\">A function to test each element for a condition.</param>\n        /// <returns>An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"predicate\"/> is null.</exception>\n        /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>\n        public static IObservable<bool> All<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (predicate == null)\n            {\n                throw new ArgumentNullException(nameof(predicate));\n            }\n\n            return s_impl.All(source, predicate);\n        }\n\n        #endregion\n\n        #region + Any +\n\n        /// <summary>\n        /// Determines whether an observable sequence contains any elements.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">An observable sequence to check for non-emptiness.</param>\n        /// <returns>An observable sequence containing a single element determining whether the source sequence contains any elements.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>\n        public static IObservable<bool> Any<TSource>(this IObservable<TSource> source)","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Aggregates.cs#L105-L141","documentation":"The All(source, predicate) overload throws ArgumentNullException when the predicate delegate is null. Rx validates arguments eagerly in the public wrapper before delegating to s_impl.All, so a null predicate fails immediately at the call site. The doc comment explicitly lists predicate as throwing ArgumentNullException.","triggerScenarios":"Calling `source.All(null)` directly, or passing a Func field/property/returned delegate that was never initialized, e.g. `Func<int,bool> test = null; source.All(test);` — throws at Observable.Aggregates.cs line ~123.","commonSituations":"Building operator pipelines dynamically where the predicate comes from configuration or a rules engine and no rule matched; a helper method with an optional predicate parameter that is forwarded without a default; reflection-created delegates that ended up null.","solutions":["Pass a real predicate, e.g. `source.All(x => x > 0)`; if you truly want 'all pass', use `x => true`.","Guard optional predicates: `source.All(predicate ?? (_ => true))`.","Fix the rules/config layer so it always yields a compiled Func<TSource,bool> instead of null.","Add a unit test covering the null-predicate path of your pipeline builder."],"exampleFix":"// before\nFunc<int, bool> predicate = rules.GetPredicate(); // may be null\nvar all = source.All(predicate);\n\n// after\nvar all = source.All(rules.GetPredicate() ?? (_ => true));","handlingStrategy":"validation","validationCode":"if (source is null || predicate is null)\n    throw new InvalidOperationException(\"All(source, predicate) requires non-null arguments\");\nvar all = source.All(predicate);","typeGuard":"bool IsValidPredicate<TSource>(Func<TSource,bool>? p) => p is not null;","tryCatchPattern":"try { var all = source.All(predicate); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"predicate\")\n{\n    var all = source.All(_ => true); // treat missing predicate as always-true\n}","preventionTips":["Default optional predicate parameters to `_ => true` instead of null.","Ensure rule/config-to-delegate compilers always emit a Func, never null.","Wrap operator calls in a helper that centralizes null checks.","Test the null-predicate path in pipeline builder unit tests."],"tags":["rx","argument-null","predicate","all-operator"],"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"}