{"record":{"id":"d2b349a94ec1855b","repo":"dotnet/reactive","slug":"argumentnullexception-where","errorCode":null,"errorMessage":"ArgumentNullException","messagePattern":"ArgumentNullException","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Where.cs","lineNumber":27,"sourceCode":"    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> Where<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<TSource>.From(\n                source,\n                predicate,\n                static (source, predicate, observer) => source.SubscribeSafeAsync(AsyncObserver.Where(observer, predicate)));\n        }\n\n        public static IAsyncObservable<TSource> Where<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<TSource>.From(\n                source,\n                predicate,\n                static (source, predicate, observer) => source.SubscribeSafeAsync(AsyncObserver.Where(observer, predicate)));\n        }\n\n        public static IAsyncObservable<TSource> Where<TSource>(this IAsyncObservable<TSource> source, Func<TSource, int, 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<TSource>.From(\n                source,","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Where.cs#L9-L45","documentation":"The async-predicate Where overload (Func<TSource, ValueTask<bool>>) validates inputs eagerly and throws ArgumentNullException with param name 'source' when the source IAsyncObservable<TSource> is null. Note: with the parameterless ArgumentNullException constructor, the exception message does not name the parameter — the param name comes from the throw site.","triggerScenarios":"Chaining .Where(asyncPredicate) on a null IAsyncObservable<TSource>; e.g. a null returned by a preceding custom async operator or an uninitialized variable.","commonSituations":"Async factory methods (Task<IAsyncObservable<T>>) whose await result was null; cached lookups missing; code paths composing queries before the source assignment completes.","solutions":["Ensure the async source-producing method returns a non-null observable, not null.","Null-check the awaited source before composing the query.","Replace null returns in factories with AsyncObservable.Empty<TSource>()."],"exampleFix":"// before\nvar source = await GetSourceAsync(); // returns null\nvar filtered = source.Where(async x => await CheckAsync(x));\n// after\nvar source = await GetSourceAsync() ?? AsyncObservable.Empty<int>();\nvar filtered = source.Where(async x => await CheckAsync(x));","handlingStrategy":"validation","validationCode":"var source = await GetSourceAsync();\nif (source == null)\n    source = AsyncObservable.Empty<TSource>();","typeGuard":"bool HasSource<T>(IAsyncObservable<T> source) => source is not null;","tryCatchPattern":"try\n{\n    var filtered = source.Where(async x => await CheckAsync(x));\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{\n    // log the null source and use an empty observable\n}","preventionTips":["Ensure async factories await a non-null result before composition.","Return AsyncObservable.Empty<T>() rather than null from async producers.","Assert non-null after awaits in debug builds (Debug.Assert(source != null))."],"tags":["argument-null","linq-operator","async-rx","where","async-predicate"],"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"}