dotnet/reactive · error · ArgumentNullException
ArgumentNullException: selector
Error message
ArgumentNullException: selector
What it means
Observable.Replay(source, selector) throws ArgumentNullException with ParamName "selector" when the Func<IObservable<TSource>, IObservable<TResult>> argument is null (source already checked). The selector defines the multicast projection and is required.
Solutions
- Pass a valid selector lambda, e.g. source.Replay(xs => xs.Take(5)).
- If you did not want projection, use the parameterless source.Replay() overload instead.
- Fix the variable/branch that produced a null Func.
Example fix
// before Func<IObservable<int>, IObservable<int>>? sel = PickSelector(); // null var q = source.Replay(sel); // after var q = source.Replay(xs => xs.Take(5));
Defensive patterns
Strategy: validation
Validate before calling
if (selector == null) throw new InvalidOperationException("Replay selector delegate is required."); Type guard
static bool HasSelector<T, R>(Func<IObservable<T>, IObservable<R>>? sel) => sel is not null;
Try / catch
try { var q = source.Replay(selector); } catch (ArgumentNullException ex) when (ex.ParamName == "selector") { var conn = source.Replay(); /* fallback: no projection */ } Prevention
- If no projection is needed, call the parameterless Replay() overload instead of passing null.
- Build selectors with lambdas at the call site to avoid null delegate variables.
- Check you did not accidentally pass null where a Func was expected.
When it happens
Trigger: Calling source.Replay(null) where the intent was the parameterless/scheduler overload but a null Func was passed, or a selector delegate variable left unassigned.
Common situations: Conditional selector construction that fell through to null; passing a method group that failed to resolve and was silently null in dynamic/reflection-based code.
Related errors
- ArgumentNullException: scheduler
- ArgumentNullException: source
- nameof(condition)
- nameof(iterate)
- observer
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/250252be50fd1d08.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs:476
/// This operator is a specialization of Multicast using a <see cref="ReplaySubject{T}"/>.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
/// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
/// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
/// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source.</param>
/// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
/// <seealso cref="ReplaySubject{T}"/>
public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
if (selector == null)
{
throw new ArgumentNullException(nameof(selector));
}
return s_impl.Replay(source, selector);
}
/// <summary>
/// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying all notifications.
/// This operator is a specialization of Multicast using a <see cref="ReplaySubject{T}"/>.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
/// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
/// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
/// <param name="selector">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source.</param>
/// <param name="scheduler">Scheduler where connected observers within the selector function will be invoked on.</param>
/// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> or <paramref name="scheduler"/> is null.</exception>
/// <seealso cref="ReplaySubject{T}"/>
public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, IScheduler scheduler)View on GitHub (pinned to 94b5d5ab91)