dotnet/reactive · error · ArgumentNullException

ArgumentNullException: scheduler

Error message

ArgumentNullException: scheduler

What it means

Observable.Replay(source, scheduler) throws ArgumentNullException with ParamName "scheduler" when the IScheduler argument is null (source already validated non-null). Replay with a scheduler needs a valid scheduler to timestamp/serialize replays.

Solutions

  1. Pass a concrete IScheduler such as Scheduler.Default, Scheduler.Immediate, or TaskPoolScheduler.Default.
  2. Fix the config/branch that resolved the scheduler to null.
  3. Guard the call: if (scheduler == null) scheduler = Scheduler.Default;

Example fix

// before
var conn = source.Replay(null);
// after
var conn = source.Replay(Scheduler.Default);
Defensive patterns

Strategy: validation

Validate before calling

scheduler ??= Scheduler.Default; // before calling Replay

Type guard

static IScheduler NonNull(IScheduler? s) => s ?? Scheduler.Default;

Try / catch

try { var conn = source.Replay(scheduler); } catch (ArgumentNullException ex) when (ex.ParamName == "scheduler") { scheduler = Scheduler.Default; }

Prevention

When it happens

Trigger: Calling source.Replay(null) or passing a scheduler variable that was never initialized, e.g. Replay(source, defaultScheduler) where defaultScheduler is null.

Common situations: Config-based scheduler selection falling through to null, or passing Scheduler.Default typed as null in generic code.

Related errors


AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15). Data as JSON: /api/errors/46be15831fec57b1. Report an issue: GitHub.

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs:450

        /// 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>
        /// <param name="source">Source sequence whose elements will be multicasted through a single shared subscription.</param>
        /// <param name="scheduler">Scheduler where connected observers will be invoked on.</param>
        /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
        /// <remarks>Subscribers will receive all the notifications of the source.</remarks>
        /// <seealso cref="ReplaySubject{T}"/>
        public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source, IScheduler scheduler)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }

            return s_impl.Replay(source, scheduler);
        }

        /// <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>
        /// <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)
        {

View on GitHub (pinned to 94b5d5ab91)