{"record":{"id":"f0d08726dccbaa3c","repo":"dotnet/reactive","slug":"nameof-source","errorCode":null,"errorMessage":"nameof(source)","messagePattern":"nameof\\(source\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/DoWhile.cs","lineNumber":17,"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.Reactive.Disposables;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        // REVIEW: Use a tail-recursive sink.\n\n        public static IAsyncObservable<TSource> DoWhile<TSource>(IAsyncObservable<TSource> source, Func<bool> condition)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (condition == null)\n                throw new ArgumentNullException(nameof(condition));\n\n            return Create(\n                source,\n                condition,\n                static async (source, condition, observer) =>\n                {\n                    var subscription = new SerialAsyncDisposable();\n\n                    var o = default(IAsyncObserver<TSource>);\n\n                    o = AsyncObserver.CreateUnsafe<TSource>(\n                            observer.OnNextAsync,\n                            observer.OnErrorAsync,\n                            MoveNext\n                        );\n","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/DoWhile.cs#L1-L35","documentation":"Thrown by the DoWhile(source, condition) overload when the source IAsyncObservable is null. DoWhile re-runs the source until the boolean condition fails, and the library null-checks its inputs at composition time. The message names source as the null parameter.","triggerScenarios":"Calling AsyncObservable.DoWhile(null, condition) — usually when the source expression is the result of a method that returned null, a null conditional chain, or arguments passed in reverse order.","commonSituations":"Building query pipelines where an earlier factory call returned null; conditional stream selection where all branches were null; unit tests constructing operators with default values.","solutions":["Pass a non-null IAsyncObservable<TSource> as the first argument","Verify the expression producing the source actually returns a stream (e.g. it wasn't a failed Create call)","Check argument order: source comes first, condition second","Guard with a null check or fallback stream (AsyncEnumerable.Empty) before composing"],"exampleFix":"// before\nIAsyncObservable<int> source = null;\nvar res = AsyncObservable.DoWhile(source, () => keepGoing); // throws\n// after\nIAsyncObservable<int> source = GetSource() ?? AsyncObservable.Empty<int>();\nvar res = AsyncObservable.DoWhile(source, () => keepGoing);","handlingStrategy":"validation","validationCode":"if (source == null) throw new InvalidOperationException(\"DoWhile requires a non-null source\");\nvar res = AsyncObservable.DoWhile(source, condition);","typeGuard":"bool IsStreamValid<TSource>(IAsyncObservable<TSource> s) => s is not null;","tryCatchPattern":"try\n{\n    var res = AsyncObservable.DoWhile(source, condition);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{\n    res = AsyncObservable.DoWhile(AsyncObservable.Empty<TSource>(), condition);\n}","preventionTips":["Coalesce possibly-null streams with AsyncObservable.Empty<TSource>() at pipeline boundaries","Make stream factories return empty observables instead of null","Enable nullable reference types for compile-time null tracking","Validate the full chain before composing repeat operators"],"tags":["argument-null","asyncrx","dowhile-operator"],"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"}