{"record":{"id":"c7a688118915a04c","repo":"dotnet/reactive","slug":"observer-distinctuntilchanged","errorCode":null,"errorMessage":"observer","messagePattern":"observer","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/DistinctUntilChanged.cs","lineNumber":95,"sourceCode":"                throw new ArgumentNullException(nameof(source));\n            if (keySelector == null)\n                throw new ArgumentNullException(nameof(keySelector));\n            if (comparer == null)\n                throw new ArgumentNullException(nameof(comparer));\n\n            return Create(\n                source,\n                (keySelector, comparer),\n                static (source, state, observer) => source.SubscribeSafeAsync(AsyncObserver.DistinctUntilChanged(observer, state.keySelector, state.comparer)));\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> DistinctUntilChanged<TSource>(IAsyncObserver<TSource> observer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return DistinctUntilChanged(observer, x => x, EqualityComparer<TSource>.Default);\n        }\n\n        public static IAsyncObserver<TSource> DistinctUntilChanged<TSource>(IAsyncObserver<TSource> observer, IEqualityComparer<TSource> comparer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (comparer == null)\n                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));","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/DistinctUntilChanged.cs#L77-L113","documentation":"System.ArgumentNullException with ParamName 'observer' thrown by AsyncObserver.DistinctUntilChanged<TSource>(IAsyncObserver<TSource>) when the downstream observer is null. This is the observer-side factory variant used when composing custom async operators. A null observer cannot receive OnNextAsync/OnErrorAsync, so construction fails immediately.","triggerScenarios":"Calling AsyncObserver.DistinctUntilChanged(null) inside a custom operator's subscription chain.","commonSituations":"Wrapping an observer obtained from a caller that passed null; building operator chains where an earlier stage handed back a null observer; tests passing null to exercise the factory.","solutions":["Pass the actual non-null IAsyncObserver<TSource> from the enclosing subscription context.","Check why the observer variable is null — it should originate from SubscribeSafeAsync/Subscribe plumbing.","If writing an operator, propagate the observer argument rather than reconstructing it."],"exampleFix":"// before\nvar obs = AsyncObserver.DistinctUntilChanged(downstreamObserver); // downstreamObserver was null\n// after\nif (downstreamObserver == null) throw new InvalidOperationException(\"observer not provided\");\nvar obs = AsyncObserver.DistinctUntilChanged(downstreamObserver);","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));\nvar obs = AsyncObserver.DistinctUntilChanged(observer);","typeGuard":"bool IsValidObserver<TSource>(IAsyncObserver<TSource>? o) => o is not null;","tryCatchPattern":"try\n{\n    var obs = AsyncObserver.DistinctUntilChanged(observer);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\")\n{\n    throw new InvalidOperationException(\"Downstream observer was not supplied\", ex);\n}","preventionTips":["Only build observer chains from observers received via subscription callbacks","Assert observer non-null at operator entry points in custom operators","Keep observer plumbing arguments flowing; never hardcode null"],"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"}