dotnet/reactive · error · ArgumentNullException
Thrown when condition is null (ArgumentNullException, param…
Error message
Thrown when condition is null (ArgumentNullException, param name: condition)
What it means
DoWhile repeats the source sequence as long as the postcondition delegate holds; a null condition would make the repeat decision undefined, so the operator throws ArgumentNullException for parameter 'condition'. Fix: pass a non-null Func<bool>.
Solutions
- Supply a valid Func<bool> — use () => false if 'no repeat' is intended.
- Verify the delegate source (field/factory) is initialized before the call.
- Add a null guard or default at the point where the condition is obtained.
Example fix
// before Func<bool> cond = GetCondition(); // may return null var result = source.DoWhile(cond); // after var result = source.DoWhile(cond ?? (() => false));
Defensive patterns
Strategy: validation
Validate before calling
if (condition is null) throw new ArgumentNullException(nameof(condition)); DoWhile(source, condition ?? (() => false));
Type guard
bool HasCondition(Func<bool> c) => c is not null;
Try / catch
try { var q = source.DoWhile(condition); }
catch (ArgumentNullException ex) when (ex.ParamName == "condition") { /* use default condition */ } Prevention
- Initialize delegate fields at declaration, not lazily.
- Avoid obj?.Method passing which silently yields null.
- Provide defaults (() => false) for optional conditions.
- Use nullable reference types to catch uninitialized delegates.
When it happens
Trigger: Calling DoWhile(source, null) — e.g. the condition Func<bool> came from an optional configuration or a nullable delegate field.
Common situations: A delegate stored in a nullable field/property not yet initialized; a factory method returning null for the condition; passing a method group on a null object (obj?.Condition compiles to null).
Related errors
- Thrown when finallyAction is null (ArgumentNullException…
- Thrown when onNext is null (ArgumentNullException, param…
- Thrown when resultSelector is null (ArgumentNullException…
- Thrown when selector is null (ArgumentNullException, param…
- Value cannot be null. (Parameter 'handler')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/b58290c7d455b8be.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/DoWhile.cs:23
using System.Collections.Generic;
namespace System.Linq
{
public static partial class EnumerableEx
{
/// <summary>
/// Generates an enumerable sequence by repeating a source sequence as long as the given loop postcondition holds.
/// </summary>
/// <typeparam name="TResult">Result sequence element type.</typeparam>
/// <param name="source">Source sequence to repeat while the condition evaluates true.</param>
/// <param name="condition">Loop condition.</param>
/// <returns>Sequence generated by repeating the given sequence until the condition evaluates to false.</returns>
public static IEnumerable<TResult> DoWhile<TResult>(this IEnumerable<TResult> source, Func<bool> condition)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (condition == null)
throw new ArgumentNullException(nameof(condition));
return source.Concat(While(condition, source));
}
}
}
View on GitHub (pinned to 94b5d5ab91)