{"record":{"id":"eea3008543055e79","repo":"dotnet/reactive","slug":"argumentnullexception-nameof-predicate","errorCode":null,"errorMessage":"ArgumentNullException(nameof(predicate))","messagePattern":"ArgumentNullException\\(nameof\\(predicate\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Where.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<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)));","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Where.cs#L1-L34","documentation":"The synchronous-predicate Where extension throws ArgumentNullException with param name 'predicate' when the Func<TSource, bool> filter delegate is null. The check runs eagerly at composition time so the failure names the offending parameter.","triggerScenarios":"Calling source.Where(null) with the sync predicate overload — a null lambda, an uninitialized Func variable, or a null result from a predicate-builder helper.","commonSituations":"Predicates selected from a dictionary of filters where the key lookup missed; optional predicate parameters defaulting to null; serialization/generation pipelines emitting null delegates.","solutions":["Pass a valid predicate, e.g. x => x % 2 == 0.","If the predicate is optional, substitute a default (x => true) before calling Where.","Fix the filter-registry/builder so it never returns null (return a pass-through predicate instead)."],"exampleFix":"// before\nFunc<int, bool> pred = GetFilter(name); // may return null\nvar filtered = source.Where(pred);\n// after\nvar pred = GetFilter(name) ?? (_ => true);\nvar filtered = source.Where(pred);","handlingStrategy":"validation","validationCode":"if (predicate == null)\n    predicate = _ => true; // pass-through default","typeGuard":"bool HasPredicate<T>(Func<T, bool> p) => p is not null;","tryCatchPattern":"try\n{\n    var filtered = source.Where(predicate);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"predicate\")\n{\n    // fall back to an unfiltered source or fix the filter registry\n}","preventionTips":["Default optional predicate parameters to _ => true instead of null.","Use TryGetValue for filter lookups and coalesce with a pass-through.","Unit-test predicate builders to guarantee non-null output."],"tags":["argument-null","linq-operator","async-rx","where","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"}