dotnet/reactive · error · ArgumentNullException

action (Parameter 'action')

Error message

action (Parameter 'action')

What it means

LocalScheduler.Schedule<TState>(state, action) — the base class for concurrency-restricted schedulers like NewThreadScheduler/DefaultScheduler — throws ArgumentNullException when action is null, before forwarding to the TimeSpan overload with TimeSpan.Zero.

Solutions

  1. Pass a non-null lambda to Schedule; find the unassigned delegate upstream.
  2. Guard at your abstraction layer: Require.NotNull(action, nameof(action)).
  3. If work is optional, wrap: action ?? ((s, st) => Disposable.Empty).

Example fix

// before
Action<int> cb = null;
Scheduler.Default.Schedule(0, (s, st) => { cb(st); return Disposable.Empty; }); // throws

// after
cb ??= _ => { };
Scheduler.Default.Schedule(0, (s, st) => { cb(st); return Disposable.Empty; });
Defensive patterns

Strategy: validation

Validate before calling

if (action is null) throw new ArgumentNullException(nameof(action));
Scheduler.Default.Schedule(state, action);

Type guard

static bool ValidWork<TState>(Func<IScheduler, TState, IDisposable>? a) => a is not null;

Try / catch

try { Scheduler.Default.Schedule(state, action); }
catch (ArgumentNullException ex) when (ex.ParamName == "action")
{
    // user callback hook was never registered
}

Prevention

When it happens

Trigger: Calling any derived scheduler (e.g. Scheduler.Default, NewThreadScheduler.Default) with the immediate-overload and a null action, or Rx operators (Tick, ScheduleAction, recursion helpers) passing a null delegate through.

Common situations: Using Rx default scheduling (Observable.Timer, Delay, SubscribeOn) with user callbacks that are null; plugin/observer patterns where a callback hook was never registered.

Related errors


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

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.cs:29

    {
        /// <summary>
        /// Gets the scheduler's notion of current time.
        /// </summary>
        public virtual DateTimeOffset Now => Scheduler.Now;

        /// <summary>
        /// Schedules an action to be executed.
        /// </summary>
        /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
        /// <param name="state">State passed to the action to be executed.</param>
        /// <param name="action">Action to be executed.</param>
        /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
        public virtual IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            return Schedule(state, TimeSpan.Zero, action);
        }

        /// <summary>
        /// Schedules an action to be executed after dueTime.
        /// </summary>
        /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
        /// <param name="state">State passed to the action to be executed.</param>
        /// <param name="action">Action to be executed.</param>
        /// <param name="dueTime">Relative time after which to execute the action.</param>
        /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
        public abstract IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action);

        /// <summary>
        /// Schedules an action to be executed at dueTime.
        /// </summary>

View on GitHub (pinned to 94b5d5ab91)