{"record":{"id":"03eb5eb710b0f218","repo":"dotnet/reactive","slug":"nameof-condition","errorCode":null,"errorMessage":"nameof(condition)","messagePattern":"nameof\\(condition\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/DoWhile.cs","lineNumber":19,"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\n                    async Task Subscribe()\n                    {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/DoWhile.cs#L1-L37","documentation":"Thrown by DoWhile(source, condition) when the condition Func<bool> delegate is null. The condition decides after each emission whether to repeat the source, so it is required; the library rejects null eagerly. The message names condition.","triggerScenarios":"Calling DoWhile with a valid source but a null condition delegate — a null method group, an uninitialized Func field, or swapped arguments.","commonSituations":"Feature-flag-gated predicates left null; passing a Func<ValueTask<bool>> where Func<bool> was expected via a null-returning conversion helper; test scaffolding with default parameters.","solutions":["Supply a non-null Func<bool> condition","Verify the delegate expression evaluates to a real function (e.g. the object holding the method is not null)","For an async condition, use the DoWhile(source, Func<ValueTask<bool>>) overload with a non-null delegate","Default the condition to () => false if repetition is not desired"],"exampleFix":"// before\nFunc<bool> cond = null;\nAsyncObservable.DoWhile(source, cond); // throws\n// after\nFunc<bool> cond = () => attempts < maxAttempts;\nAsyncObservable.DoWhile(source, cond);","handlingStrategy":"validation","validationCode":"if (condition == null) throw new InvalidOperationException(\"DoWhile requires a non-null condition\");\nvar res = AsyncObservable.DoWhile(source, condition);","typeGuard":"bool IsValidCondition(Func<bool> c) => c is not null;","tryCatchPattern":"try\n{\n    var res = AsyncObservable.DoWhile(source, condition);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"condition\")\n{\n    res = AsyncObservable.DoWhile(source, () => false); // never repeats\n}","preventionTips":["Default predicates to () => false when unset rather than leaving them null","Use () => new ValueTask<bool>(b) / async lambdas for async conditions and the matching overload","Initialize Func fields at declaration","Beware null method groups: obj.Conditions when obj may be null"],"tags":["argument-null","delegate","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"}