{"record":{"id":"94fcb83a2167acc5","repo":"dotnet/reactive","slug":"predicate-single","errorCode":null,"errorMessage":"predicate","messagePattern":"predicate","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Single.cs","lineNumber":103,"sourceCode":"            );\n        }\n\n        public static IAsyncObserver<TSource> Single<TSource>(IAsyncObserver<TSource> observer, Func<TSource, bool> predicate)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (predicate == null)\n                throw new ArgumentNullException(nameof(predicate));\n\n            return Where(Single(observer), predicate);\n        }\n\n        public static IAsyncObserver<TSource> Single<TSource>(IAsyncObserver<TSource> observer, Func<TSource, ValueTask<bool>> predicate)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (predicate == null)\n                throw new ArgumentNullException(nameof(predicate));\n\n            return Where(Single(observer), predicate);\n        }\n    }\n}\n","sourceCodeStart":85,"sourceCodeEnd":109,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Single.cs#L85-L109","documentation":"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.","triggerScenarios":"Calling AsyncObserver.Single(observer, (Func<TSource,ValueTask<bool>>)null) with a null async predicate.","commonSituations":"Overload-resolution confusion where a null literal bound to the ValueTask overload; predicates not yet initialized in dynamic pipelines.","solutions":["Pass a valid ValueTask<bool>-returning predicate, or cast a lambda to the desired overload","Use the sync predicate overload when no async work is required","Use the predicateless overload if no filter is intended"],"exampleFix":"// before\nvar obs = AsyncObserver.Single<int>(downstream, (Func<int, ValueTask<bool>>)null);\n// after\nvar obs = AsyncObserver.Single<int>(downstream, async x => await CheckAsync(x));","handlingStrategy":"validation","validationCode":"if (asyncPredicate is null) throw new ArgumentNullException(nameof(predicate));","typeGuard":"static bool IsValidAsyncPredicate<T>(Func<T, ValueTask<bool>>? p) => p is not null;","tryCatchPattern":"try { var o = AsyncObserver.Single<T>(observer, asyncPred); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"predicate\") { /* supply async predicate */ }","preventionTips":["Cast null/lambda arguments explicitly so the intended overload is chosen","Initialize async predicates at the call site as lambdas","Document which overload accepts ValueTask predicates to avoid null-binding mistakes"],"tags":["csharp","null-check","async-predicate","asyncrx"],"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"}