dotnet/reactive · error · ArgumentNullException
action (Value cannot be null)
Error message
action (Value cannot be null)
What it means
SchedulePeriodic<TState>(IScheduler, TState, TimeSpan, Func<TState,TState>) throws ArgumentNullException when the per-tick Func<TState,TState> action is null. This overload's action both observes and returns the next state, so Rx validates it before delegating to SchedulePeriodic_. Like other argument checks, it fires at the call site.
Solutions
- Pass a non-null state-transforming Func, e.g. scheduler.SchedulePeriodic(state, period, s => Tick(s))
- Validate with ArgumentNullException.ThrowIfNull(action) at your own boundary for a clearer message
- If the Func comes from a registry/factory, add a fallback (identity function) or fail fast when it cannot be resolved
Example fix
// before Func<int, int> tick = reducers[name]; // missing key -> null scheduler.SchedulePeriodic(state, period, tick); // after Func<int, int> tick = reducers.TryGetValue(name, out var r) ? r : s => s; scheduler.SchedulePeriodic(state, period, tick);
Defensive patterns
Strategy: validation
Validate before calling
if (action is null) throw new ArgumentNullException(nameof(action)); scheduler.SchedulePeriodic(state, period, action);
Type guard
bool HasTickFunction<TState>(Func<TState, TState> a) => a is not null;
Try / catch
try { scheduler.SchedulePeriodic(state, period, action); }
catch (ArgumentNullException ex) when (ex.ParamName == "action") { /* use identity fallback: s => s */ } Prevention
- Never allow delegate-producing lookups to return null; use TryGetValue with fallback
- Declare tick functions as non-nullable under NRT
- Unit-test reducer/registry tables for missing keys
When it happens
Trigger: Calling scheduler.SchedulePeriodic(state, period, (Func<TState,TState>)null), passing an unassigned delegate field, or a function-returning-func helper that returned null.
Common situations: State-update functions built dynamically (e.g. a reducer table lookup that missed), delegates captured from an event or plugin that was not loaded, and refactors where the lambda was deleted but the call kept.
Related errors
- action
- action (Parameter 'action')
- action (Parameter 'action')
- ArgumentNullException(nameof(scheduler))
- comparer (Parameter 'comparer')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/9e17025288d14859.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs:42
/// <param name="action">Action to be executed, potentially updating the state.</param>
/// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
/// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
public static IDisposable SchedulePeriodic<TState>(this IScheduler scheduler, TState state, TimeSpan period, Func<TState, TState> action)
{
if (scheduler == null)
{
throw new ArgumentNullException(nameof(scheduler));
}
if (period < TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(period));
}
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
return SchedulePeriodic_(scheduler, state, period, action);
}
/// <summary>
/// Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities.
/// If the scheduler supports periodic scheduling, the request will be forwarded to the periodic scheduling implementation.
/// If the scheduler provides stopwatch functionality, the periodic task will be emulated using recursive scheduling with a stopwatch to correct for time slippage.
/// Otherwise, the periodic task will be emulated using recursive scheduling.
/// </summary>
/// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
/// <param name="scheduler">Scheduler to execute the action on.</param>
/// <param name="state">State passed to the action to be executed.</param>
/// <param name="period">Period for running the work periodically.</param>
/// <param name="action">Action to be executed.</param>
/// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
/// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>View on GitHub (pinned to 94b5d5ab91)