dotnet/reactive · error · ArgumentNullException
throw new ArgumentNullException(nameof(iteratorMethod))
Error message
throw new ArgumentNullException(nameof(iteratorMethod))
What it means
QbservableEx.Create(provider, iteratorMethod) requires the generator method as an Expression<Func<IEnumerable<IObservable<object>>>> so it can be serialized into the query expression tree. A null iteratorMethod throws ArgumentNullException named 'iteratorMethod'. The expression is needed because qbservable queries are transmitted as expression trees, not compiled delegates.
Solutions
- Supply a real expression lambda, e.g. () => new[] { Observable.Return(1) } typed as IEnumerable<IObservable<object>>
- If the iterator is optional, branch: skip Create entirely when iteratorMethod is null
- Fix the factory/reflective builder that returned a null expression
Example fix
// before
Qbservable.Create(provider, iteratorMethod); // iteratorMethod is null
// after
Expression<Func<IEnumerable<IObservable<object>>>> iteratorMethod =
() => new[] { Observable.Return((object)42) };
Qbservable.Create(provider, iteratorMethod); Defensive patterns
Strategy: validation
Validate before calling
if (iteratorMethod == null)
throw new InvalidOperationException("iteratorMethod expression is required for Qbservable.Create"); Type guard
bool HasIterator(Expression<Func<IEnumerable<IObservable<object>>>> m) => m is not null;
Try / catch
try
{
var query = Qbservable.Create(provider, iteratorMethod);
}
catch (ArgumentNullException ex) when (ex.ParamName == "iteratorMethod")
{
logger.LogError(ex, "Iterator expression was null");
} Prevention
- Always pass literal expression lambdas to Create, not nullable variables
- Remember Qbservable APIs require Expression<>, not plain Func<>
- Skip the Create call entirely when the iterator is not defined
When it happens
Trigger: Calling Qbservable.Create(provider, null) — usually when the iterator lambda was built conditionally, stored in a nullable variable, or produced by reflection/factory code that returned null.
Common situations: Building iterator methods dynamically and passing an unassigned variable; refactoring where the lambda was removed but the call remained; conditional query construction where only some branches define the iterator.
Related errors
- selector
- throw new ArgumentNullException(nameof(provider))
- throw new ArgumentNullException(nameof(selector))
- throw new ArgumentNullException(nameof(sixteenth))
- throw new ArgumentNullException(nameof(source))
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/fbfb7fe5542b4e28.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs:967
);
}
#if !STABLE
/// <summary>
/// Subscribes to each observable sequence returned by the iteratorMethod in sequence and produces a Unit value on the resulting sequence for each step of the iteration.
/// </summary>
/// <param name="provider">Query provider used to construct the <see cref="IQbservable{T}"/> data source.</param>
/// <param name="iteratorMethod">Iterator method that drives the resulting observable sequence.</param>
/// <returns>An observable sequence obtained by running the iterator and returning Unit values for each iteration step.</returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="iteratorMethod" /> is null.</exception>
[Experimental]
public static IQbservable<Unit> Create(this IQbservableProvider provider, Expression<Func<IEnumerable<IObservable<object>>>> iteratorMethod)
{
if (provider == null)
throw new ArgumentNullException(nameof(provider));
if (iteratorMethod == null)
throw new ArgumentNullException(nameof(iteratorMethod));
return provider.CreateQuery<Unit>(
Expression.Call(
null,
new Func<IQbservableProvider, Expression<Func<IEnumerable<IObservable<object>>>>, IQbservable<Unit>>(Create).Method,
Expression.Constant(provider, typeof(IQbservableProvider)),
iteratorMethod
)
);
}
#endif
#if !STABLE
/// <summary>
/// Subscribes to each observable sequence returned by the iteratorMethod in sequence and returns the observable sequence of values sent to the observer given to the iteratorMethod.
/// </summary>
/// <param name="provider">Query provider used to construct the <see cref="IQbservable{T}"/> data source.</param>
/// <typeparam name="TResult">The type of the elements in the produced sequence.</typeparam>View on GitHub (pinned to 94b5d5ab91)