{"record":{"id":"e16ef3ab02c28c4b","repo":"dotnet/reactive","slug":"argumentnullexception-nameof-source","errorCode":null,"errorMessage":"ArgumentNullException(nameof(source))","messagePattern":"ArgumentNullException\\(nameof\\(source\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs","lineNumber":14,"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,","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs#L1-L32","documentation":"The Do extension method Do<TSource>(this IAsyncObservable<TSource> source, IObserver<TSource> observer) throws ArgumentNullException when source is null. Do is a side-effect tap over a source sequence; there is nothing to tap into if the source is null, so it fails fast at composition time.","triggerScenarios":"Invoking source.Do(observer) as an extension on a null IAsyncObservable<TSource>, or calling AsyncObservable.Do(null, observer) directly.","commonSituations":"An observable factory/config-driven pipeline that produced null; operator chains where an earlier step returned null instead of a sequence; nullable field holding the pipeline never initialized.","solutions":["Ensure the source IAsyncObservable<TSource> is non-null before calling Do (check how it was constructed).","If the source may be absent, coalesce to an empty observable via AsyncObservable.Empty<TSource>() rather than null.","Null-check or throw a meaningful exception at the pipeline-building site."],"exampleFix":"// before\nvar tapped = pipeline?.Do(spyObserver); // pipeline null -> ArgumentNullException\n// after\nvar tapped = (pipeline ?? AsyncObservable.Empty<int>()).Do(spyObserver);","handlingStrategy":"validation","validationCode":"if (source is null) throw new InvalidOperationException(\"source observable must be built before Do\");\nvar tapped = source.Do(observer);","typeGuard":"static bool IsValidSource<TSource>(IAsyncObservable<TSource>? s) => s is not null;","tryCatchPattern":"try { var tapped = source.Do(observer); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* rebuild the source pipeline */ }","preventionTips":["Ensure factory methods never return null observables - return Empty on failure paths.","Use nullable annotations so null pipeline fields are caught at compile time.","Build pipelines in one place and assert non-null before chaining operators."],"tags":["argument-null","do-operator","async-rx","extension-method"],"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"}