{"record":{"id":"265db92e8796a128","repo":"dotnet/reactive","slug":"action-value-cannot-be-null-scheduler-recursive","errorCode":null,"errorMessage":"action (Value cannot be null)","messagePattern":"action \\(Value cannot be null\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Recursive.cs","lineNumber":27,"sourceCode":"    public static partial class Scheduler\n    {\n        /// <summary>\n        /// Schedules an action to be executed recursively.\n        /// </summary>\n        /// <param name=\"scheduler\">Scheduler to execute the recursive action on.</param>\n        /// <param name=\"action\">Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action.</param>\n        /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"scheduler\"/> or <paramref name=\"action\"/> is <c>null</c>.</exception>\n        public static IDisposable Schedule(this IScheduler scheduler, Action<Action> action)\n        {\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            if (action == null)\n            {\n                throw new ArgumentNullException(nameof(action));\n            }\n\n            return scheduler.Schedule(action, static (a, self) => a(() => self(a)));\n        }\n\n        /// <summary>\n        /// Schedules an action to be executed recursively.\n        /// </summary>\n        /// <typeparam name=\"TState\">The type of the state passed to the scheduled action.</typeparam>\n        /// <param name=\"scheduler\">Scheduler to execute the recursive action on.</param>\n        /// <param name=\"state\">State passed to the action to be executed.</param>\n        /// <param name=\"action\">Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in recursive invocation state.</param>\n        /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"scheduler\"/> or <paramref name=\"action\"/> is <c>null</c>.</exception>\n        public static IDisposable Schedule<TState>(this IScheduler scheduler, TState state, Action<TState, Action<TState>> action)\n        {\n            if (scheduler == null)\n            {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Recursive.cs#L9-L45","documentation":"This ArgumentNullException is thrown by the Schedule(this IScheduler, Action<Action>) extension in Scheduler.Recursive.cs when the recursive action delegate is null. Rx's scheduler extensions validate arguments eagerly at the call site so a null delegate fails immediately rather than surfacing later inside the scheduler's queue. Only the action parameter is null here; the scheduler parameter was already checked.","triggerScenarios":"Calling Scheduler.Schedule(scheduler, (Action<Action>)null) or Schedule<TState> overloads with a null recursive action lambda, typically because a variable holding the delegate was null or a factory returned null.","commonSituations":"Storing the recursive action in a nullable field that was not yet initialized; conditional logic that assigns the delegate only on some paths; passing the result of a function that returns null as the action.","solutions":["Ensure the Action<Action> delegate passed to Schedule is non-null before calling.","If the delegate comes from a variable or factory, initialize or provide a default implementation.","Guard the call site: only invoke Schedule when the action was actually constructed."],"exampleFix":"// before\nAction<Action> act = GetAction(); // may return null\nScheduler.Schedule(scheduler, act);\n// after\nAction<Action> act = GetAction() ?? (_ => { });\nScheduler.Schedule(scheduler, act);","handlingStrategy":"validation","validationCode":"if (action == null) throw new InvalidOperationException(\"Recursive action must be provided before scheduling\");","typeGuard":"bool IsValidAction(Action<Action> a) => a is not null;","tryCatchPattern":"try { Scheduler.Schedule(scheduler, action); } catch (ArgumentNullException ex) when (ex.ParamName == \"action\") { /* log and supply default action */ }","preventionTips":["Never store scheduled delegates in nullable fields; initialize at construction.","Wrap scheduler setup in a factory that guarantees non-null delegates.","Add unit tests covering the recursive scheduling setup path."],"tags":["null-argument","scheduler","reactive-extensions"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}