{"record":{"id":"d9c87ac4dcfaeb1c","repo":"dotnet/reactive","slug":"condition-observable-imperative","errorCode":null,"errorMessage":"condition","messagePattern":"condition","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Imperative.cs","lineNumber":228,"sourceCode":"\n        /// <summary>\n        /// Repeats the given <paramref name=\"source\"/> as long as the specified <paramref name=\"condition\"/> holds, where the <paramref name=\"condition\"/> is evaluated after each repeated <paramref name=\"source\"/> completed.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source to repeat as long as the <paramref name=\"condition\"/> function evaluates to true.</param>\n        /// <param name=\"condition\">Condition that will be evaluated upon the completion of an iteration through the <paramref name=\"source\"/>, to determine whether repetition of the source is required.</param>\n        /// <returns>The observable sequence obtained by concatenating the <paramref name=\"source\"/> sequence as long as the <paramref name=\"condition\"/> holds.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"condition\"/> is null.</exception>\n        public static IObservable<TSource> DoWhile<TSource>(this IObservable<TSource> source, Func<bool> condition)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (condition == null)\n            {\n                throw new ArgumentNullException(nameof(condition));\n            }\n\n            return s_impl.DoWhile(source, condition);\n        }\n\n        #endregion\n\n        #region + For +\n\n        /// <summary>\n        /// Concatenates the observable sequences obtained by running the <paramref name=\"resultSelector\"/> for each element in the given enumerable <paramref name=\"source\"/>.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the enumerable source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the observable result sequence.</typeparam>\n        /// <param name=\"source\">Enumerable source for which each element will be mapped onto an observable source that will be concatenated in the result sequence.</param>\n        /// <param name=\"resultSelector\">Function to select an observable source for each element in the <paramref name=\"source\"/>.</param>\n        /// <returns>The observable sequence obtained by concatenating the sources returned by <paramref name=\"resultSelector\"/> for each element in the <paramref name=\"source\"/>.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"resultSelector\"/> is null.</exception>","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Imperative.cs#L210-L246","documentation":"DoWhile evaluates its condition delegate after each repetition of the source; a null condition would make repetition undecidable. The wrapper throws ArgumentNullException for the condition parameter before any subscription occurs.","triggerScenarios":"Calling Observable.DoWhile(source, null) or passing a Func<bool> variable/field that was never assigned.","commonSituations":"Storing the loop predicate in a nullable delegate field, conditional predicate setup that skipped assignment, or refactoring that renamed the condition method leaving null behind.","solutions":["Supply a concrete Func<bool>, e.g. () => shouldContinue, even if it always returns false.","Null-check or default-initialize the condition delegate before the call.","If no repetition is desired, drop DoWhile entirely and subscribe to the source directly."],"exampleFix":"// before\nFunc<bool> cond = null;\nvar result = source.DoWhile(cond);\n// after\nFunc<bool> cond = () => shouldRepeat;\nvar result = source.DoWhile(cond);","handlingStrategy":"validation","validationCode":"condition ??= () => false;","typeGuard":"bool IsValidCondition(Func<bool> c) => c is not null;","tryCatchPattern":"try { var result = source.DoWhile(condition); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"condition\") { /* supply default predicate */ }","preventionTips":["Default-initialize predicate fields (e.g. = () => false) instead of leaving them null.","Prefer lambdas inline at the call site over nullable delegate variables.","Validate all delegate arguments at the boundary of your own helper methods."],"tags":["null-check","delegate","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}