dotnet/reactive · error · ArgumentNullException

action (Parameter 'action')

Error message

action (Parameter 'action')

What it means

ScheduleAsync<TState> validates its second argument, the async action, after validating the scheduler. Passing a null action delegate throws ArgumentNullException('action') because there is no work to schedule.

Solutions

  1. Ensure the async lambda/delegate is provided and non-null at the call site.
  2. Guard: if the handler is missing, skip the scheduling instead of calling with null.
  3. Fix the factory/lookup that returns the action so it produces a valid delegate.

Example fix

// before
scheduler.ScheduleAsync(state, action); // action may be null
// after
if (action != null)
    scheduler.ScheduleAsync(state, action);
Defensive patterns

Strategy: validation

Validate before calling

if (asyncAction == null)
    return; // or throw a domain-specific error
scheduler.ScheduleAsync(state, asyncAction);

Type guard

static bool HasWork<TState>(Func<IScheduler, TState, CancellationToken, Task> a) => a is not null;

Try / catch

try { scheduler.ScheduleAsync(state, action); }
catch (ArgumentNullException ex) when (ex.ParamName == "action")
{
    logger.LogWarning("No async action configured; skipping scheduled work.");
}

Prevention

When it happens

Trigger: Calling `scheduler.ScheduleAsync(state, null)` — typically when the action comes from a variable, a strategy lookup, or an optional callback that was never assigned.

Common situations: Conditional handler registration where the handler is missing; refactorings that made a callback optional without guarding the call site.

Related errors


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

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs:172

        /// <summary>
        /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
        /// </summary>
        /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
        /// <param name="scheduler">Scheduler to schedule work on.</param>
        /// <param name="state">State to pass to the asynchronous method.</param>
        /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
        /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
        public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task> action)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }

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

            return ScheduleAsync_(scheduler, state, action);
        }

        /// <summary>
        /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
        /// </summary>
        /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
        /// <param name="scheduler">Scheduler to schedule work on.</param>
        /// <param name="state">State to pass to the asynchronous method.</param>
        /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
        /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
        public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
        {
            if (scheduler == null)
            {

View on GitHub (pinned to 94b5d5ab91)