{"record":{"id":"c12ea99b37013094","repo":"dotnet/reactive","slug":"source-distinctuntilchanged","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/DistinctUntilChanged.cs","lineNumber":15,"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.Collections.Generic;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> DistinctUntilChanged<TSource>(IAsyncObservable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return Create(source, static (source, observer) => source.SubscribeSafeAsync(AsyncObserver.DistinctUntilChanged(observer)));\n        }\n\n        public static IAsyncObservable<TSource> DistinctUntilChanged<TSource>(IAsyncObservable<TSource> source, IEqualityComparer<TSource> comparer)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (comparer == null)\n                throw new ArgumentNullException(nameof(comparer));\n\n            return Create(\n                source,\n                comparer,\n                static (source, comparer, observer) => source.SubscribeSafeAsync(AsyncObserver.DistinctUntilChanged(observer, comparer)));\n        }\n\n        public static IAsyncObservable<TSource> DistinctUntilChanged<TSource, TKey>(IAsyncObservable<TSource> source, Func<TSource, TKey> keySelector)","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/DistinctUntilChanged.cs#L1-L33","documentation":"This is a standard ArgumentNullException raised synchronously by the DistinctUntilChanged extension method before any subscription happens. The library validates its arguments eagerly so that a null source is reported at the call site rather than surfacing later as a NullReferenceException inside the async subscription pipeline. Passing a null IAsyncObservable<TSource> is never valid.","triggerScenarios":"Calling AsyncObservable.DistinctUntilChanged(source) with source == null, e.g. a method returned null instead of an observable, or a nullable field was not initialized.","commonSituations":"Chaining operators where an earlier factory method returned null; conditional pipelines where the source variable is null on some code path; refactoring that removed a null check upstream.","solutions":["Ensure the observable passed to DistinctUntilChanged is non-null before calling","Check why the upstream producer returned null (failed factory, uninitialized field) and fix that","Coalesce with AsyncObservable.Empty<TSource>() if a null source is legitimate in your domain"],"exampleFix":"// before\nvar result = source.DistinctUntilChanged(); // source may be null\n// after\nvar result = (source ?? AsyncObservable.Empty<int>()).DistinctUntilChanged();","handlingStrategy":"validation","validationCode":"if (source is null) throw new ArgumentNullException(nameof(source));","typeGuard":"static bool HasSource<T>(IAsyncObservable<T>? s) => s is not null;","tryCatchPattern":"try { var result = AsyncObservable.DistinctUntilChanged(src); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* substitute empty or log */ }","preventionTips":["Enable nullable reference types (enable) so the compiler flags null observables","Never let factory methods return null observables; return AsyncObservable.Empty instead","Validate pipeline inputs once at the pipeline boundary"],"tags":["null-argument","argument-validation","asyncrx"],"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"}