dotnet/reactive · error · ArgumentNullException
null
Error message
null
What it means
QueryableEx.Do<TSource>(IQueryable<TSource>, IObserver<TSource>) throws ArgumentNullException for a null source or observer; this entry corresponds to the null-argument failure surfaced at the Do operator (the message text is not preserved in this record, but the throwing region only contains the two ArgumentNullException guards). The operator wraps the observer callbacks into the query expression tree so side effects run during enumeration.
Solutions
- Ensure both the queryable and the IObserver<TSource> are non-null before calling Do.
- Initialize or substitute a default observer (e.g. an empty/no-op observer) when one is unavailable.
- Null-check the pipeline stage that should have produced the source query.
Example fix
// before query.Do(myObserver); // myObserver may be null // after if (myObserver == null) myObserver = new NopObserver<T>(); query.Do(myObserver);
Defensive patterns
Strategy: validation
Validate before calling
if (source is null || observer is null) throw new InvalidOperationException("Do requires non-null source and observer"); Type guard
static bool CanDo<T>(IQueryable<T>? q, IObserver<T>? o) => q is not null && o is not null;
Try / catch
try { return source.Do(observer); }
catch (ArgumentNullException ex) { throw new InvalidOperationException("Do() arguments must be non-null", ex); } Prevention
- Substitute a no-op observer when logging/telemetry observers are unavailable.
- Check that the query factory method cannot return null.
- Assert non-null inputs in unit tests for query pipelines.
When it happens
Trigger: Calling Do(source, observer) with either a null IQueryable<TSource> or a null IObserver<TSource>; both parameters are validated before Provider.CreateQuery is invoked.
Common situations: Passing a query produced by a method that returned null, or an observer field not yet initialized (e.g. logging observer constructed lazily but used before assignment).
Related errors
- Value cannot be null. (Parameter 'observer')
- Argument cannot be null (Parameter name: observer)
- throw new ArgumentNullException(nameof(observer));
- observer
- Value cannot be null. (Parameter 'observer')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/93b566969f78a066.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive.Providers/System/Linq/QueryableEx.Generated.cs:1559
public static IEnumerable<TSource> Do<TSource>(IEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted)
{
return EnumerableEx.Do(source, onNext, onError, onCompleted);
}
#pragma warning restore 1591
/// <summary>
/// Lazily invokes observer methods for each value in the sequence, and upon successful or exceptional termination.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="source">Source sequence.</param>
/// <param name="observer">Observer to invoke notification calls on.</param>
/// <returns>Sequence exhibiting the side-effects of observer method invocation upon enumeration.</returns>
public static IQueryable<TSource> Do<TSource>(this IQueryable<TSource> source, IObserver<TSource> observer)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (observer == null)
throw new ArgumentNullException(nameof(observer));
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
source.Expression,
Expression.Constant(observer, typeof(IObserver<TSource>))
)
);
}
#pragma warning disable 1591
[EditorBrowsable(EditorBrowsableState.Never)]
public static IEnumerable<TSource> Do<TSource>(IEnumerable<TSource> source, IObserver<TSource> observer)
{
return EnumerableEx.Do(source, observer);
}
#pragma warning restore 1591View on GitHub (pinned to 94b5d5ab91)