{"record":{"id":"042cb7b69e6b7012","repo":"dotnet/reactive","slug":"argumentnullexception-nameof-observer","errorCode":null,"errorMessage":"ArgumentNullException(nameof(observer))","messagePattern":"ArgumentNullException\\(nameof\\(observer\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/DistinctUntilChanged.cs","lineNumber":123,"sourceCode":"                throw new ArgumentNullException(nameof(comparer));\n\n            return DistinctUntilChanged(observer, x => x, comparer);\n        }\n\n        public static IAsyncObserver<TSource> DistinctUntilChanged<TSource, TKey>(IAsyncObserver<TSource> observer, Func<TSource, TKey> keySelector)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (keySelector == null)\n                throw new ArgumentNullException(nameof(keySelector));\n\n            return DistinctUntilChanged(observer, keySelector, EqualityComparer<TKey>.Default);\n        }\n\n        public static IAsyncObserver<TSource> DistinctUntilChanged<TSource, TKey>(IAsyncObserver<TSource> observer, Func<TSource, ValueTask<TKey>> keySelector)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (keySelector == null)\n                throw new ArgumentNullException(nameof(keySelector));\n\n            return DistinctUntilChanged(observer, keySelector, EqualityComparer<TKey>.Default);\n        }\n\n        public static IAsyncObserver<TSource> DistinctUntilChanged<TSource, TKey>(IAsyncObserver<TSource> observer, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (keySelector == null)\n                throw new ArgumentNullException(nameof(keySelector));\n            if (comparer == null)\n                throw new ArgumentNullException(nameof(comparer));\n\n            var hasCurrentKey = false;\n            var currentKey = default(TKey);\n","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/DistinctUntilChanged.cs#L105-L141","documentation":"System.ArgumentNullException with ParamName 'observer' thrown by AsyncObserver.DistinctUntilChanged<TSource,TKey>(IAsyncObserver<TSource>, Func<TSource, ValueTask<TKey>>) when the observer is null. This overload accepts an async key selector returning ValueTask<TKey>; the observer is validated first and construction aborts on null.","triggerScenarios":"Calling AsyncObserver.DistinctUntilChanged<TSource,TKey>(null, asyncKeySelector) — the async-selector overload of the observer factory.","commonSituations":"Observer variable null because an earlier factory call returned null (should not happen with valid args) or a caller-supplied observer was never provided; test scaffolding passing null.","solutions":["Pass the actual downstream observer instance.","Validate observer non-null before composing async-selector observers.","Fix the pipeline stage responsible for producing the observer."],"exampleFix":"// before\nvar o = AsyncObserver.DistinctUntilChanged<Order, int>(null, async o => await GetKeyAsync(o));\n// after\nvar o = AsyncObserver.DistinctUntilChanged<Order, int>(downstream, async o => await GetKeyAsync(o));","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));\nvar obs = AsyncObserver.DistinctUntilChanged<T, TKey>(observer, asyncKeySelector);","typeGuard":"bool IsValidObserver<TSource>(IAsyncObserver<TSource>? o) => o is not null;","tryCatchPattern":"try\n{\n    var obs = AsyncObserver.DistinctUntilChanged<T, TKey>(observer, asyncKeySelector);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\")\n{\n    // observer missing from pipeline — repair composition, not the args\n    throw;\n}","preventionTips":["Verify the observer-producing stage of your pipeline always returns an instance","Unit-test custom operators with a recording observer instead of null","Use non-nullable observer parameters in operator helpers"],"tags":["argumentnull","asyncrx","observer","validation"],"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"}