{"record":{"id":"2363f5ccf69dd98c","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-predicate-last","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'predicate')","messagePattern":"Value cannot be null\\. \\(Parameter 'predicate'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Last.cs","lineNumber":101,"sourceCode":"            );\n        }\n\n        public static IAsyncObserver<TSource> Last<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(Last(observer), predicate);\n        }\n\n        public static IAsyncObserver<TSource> Last<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(Last(observer), predicate);\n        }\n    }\n}\n","sourceCodeStart":83,"sourceCodeEnd":107,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Last.cs#L83-L107","documentation":"AsyncObserver.Last(observer, Func<TSource, ValueTask<bool>>) throws ArgumentNullException with the full message \"Value cannot be null. (Parameter 'predicate')\" when the async predicate delegate is null. Observer is checked first, then predicate.","triggerScenarios":"Calling AsyncObserver.Last(observer, (Func<TSource, ValueTask<bool>>)null); untyped null literals can be resolved to this overload and trip the guard.","commonSituations":"Passing null where an async filter is expected in config-driven query building; a cached delegate field never initialized before pipeline construction.","solutions":["Provide a valid async predicate: async x => await MatchAsync(x).","Coalesce with a default: asyncPred ?? (_ => ValueTask.FromResult(true)).","Use the non-predicate Last(observer) overload when no filtering is desired."],"exampleFix":"// before\nvar o = AsyncObserver.Last(downstream, asyncPred); // null\n// after\nvar o = AsyncObserver.Last(downstream, asyncPred ?? (_ => ValueTask.FromResult(true)));","handlingStrategy":"validation","validationCode":"if (asyncPredicate is null) asyncPredicate = static _ => ValueTask.FromResult(true);\nvar o = AsyncObserver.Last(observer, asyncPredicate);","typeGuard":"static bool HasAsyncPredicate<T>(Func<T, ValueTask<bool>>? p) => p is not null;","tryCatchPattern":"try { var o = AsyncObserver.Last(observer, asyncPredicate); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"predicate\") { var o = AsyncObserver.Last(observer); }","preventionTips":["Provide explicitly typed async lambdas when passing possibly-null filters.","Default async predicate fields at initialization time, not at use time.","Fall back to the non-predicate overload when filtering is optional."],"tags":["argument-null","predicate","valuetask"],"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"}