{"record":{"id":"60083afe372de629","repo":"dotnet/reactive","slug":"argumentnullexception-nameof-observer-do","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/Do.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> Do<TSource>(this IAsyncObservable<TSource> source, IObserver<TSource> observer)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return Create(\n                source,\n                observer,\n                static (source, observer, target) => source.SubscribeSafeAsync(AsyncObserver.Do(target, observer)));\n        }\n\n        public static IAsyncObservable<TSource> Do<TSource>(this IAsyncObservable<TSource> source, Action<TSource> onNext)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (onNext == null)\n                throw new ArgumentNullException(nameof(onNext));\n\n            return Create(\n                source,\n                onNext,\n                static (source, onNext, target) => source.SubscribeSafeAsync(AsyncObserver.Do(target, onNext)));","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs#L1-L34","documentation":"Do<TSource>(this IAsyncObservable<TSource> source, IObserver<TSource> observer) throws ArgumentNullException when the IObserver<TSource> tap observer is null. The observer receives the mirrored OnNext/OnError/OnCompleted notifications, and a null observer would fail only at first notification, so the library rejects it eagerly.","triggerScenarios":"Calling source.Do(null) or AsyncObservable.Do(source, null) with the IObserver<TSource> overload.","commonSituations":"A logging/tap observer resolved from DI that was not registered; a nullable observer field used for testing; conditional creation of the spy observer skipped by a branch.","solutions":["Pass a real IObserver<TSource> implementation (e.g. an AnonymousObserver or custom logger observer).","If the tap observer is optional, branch to a Do-free pipeline instead of passing null.","Verify DI registration/configuration for the observer dependency."],"exampleFix":"// before\nsource.Do(tapObserver); // tapObserver null\n// after\nvar tapped = tapObserver != null ? source.Do(tapObserver) : source;","handlingStrategy":"validation","validationCode":"if (tapObserver is null) throw new InvalidOperationException(\"tap observer required\");\nvar tapped = source.Do(tapObserver);","typeGuard":"static bool IsValidTap<TSource>(IObserver<TSource>? o) => o is not null;","tryCatchPattern":"try { var tapped = source.Do(observer); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\") { /* construct or register the tap observer */ }","preventionTips":["Make the tap observer optional explicitly: branch to a Do-free pipeline instead of null.","Verify DI registration for observer dependencies at application startup.","Prefer AnonymousObserver or a small inline observer for ad-hoc tapping."],"tags":["argument-null","observer","do-operator","async-rx"],"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"}