{"record":{"id":"19daa0285eaf38a9","repo":"dotnet/reactive","slug":"action-parameter-action-immediatescheduler","errorCode":null,"errorMessage":"action (Parameter 'action')","messagePattern":"action \\(Parameter 'action'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Concurrency/ImmediateScheduler.cs","lineNumber":38,"sourceCode":"\n        /// <summary>\n        /// Gets the singleton instance of the immediate scheduler.\n        /// </summary>\n        public static ImmediateScheduler Instance => StaticInstance.Value;\n\n        /// <summary>\n        /// Schedules an action to be executed.\n        /// </summary>\n        /// <typeparam name=\"TState\">The type of the state passed to the scheduled action.</typeparam>\n        /// <param name=\"state\">State passed to the action to be executed.</param>\n        /// <param name=\"action\">Action to be executed.</param>\n        /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"action\"/> is null.</exception>\n        public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)\n        {\n            if (action == null)\n            {\n                throw new ArgumentNullException(nameof(action));\n            }\n\n            return action(new AsyncLockScheduler(), state);\n        }\n\n        /// <summary>\n        /// Schedules an action to be executed after dueTime.\n        /// </summary>\n        /// <typeparam name=\"TState\">The type of the state passed to the scheduled action.</typeparam>\n        /// <param name=\"state\">State passed to the action to be executed.</param>\n        /// <param name=\"action\">Action to be executed.</param>\n        /// <param name=\"dueTime\">Relative time after which to execute the action.</param>\n        /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"action\"/> is null.</exception>\n        public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)\n        {\n            if (action == null)\n            {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Concurrency/ImmediateScheduler.cs#L20-L56","documentation":"ImmediateScheduler.Schedule<TState>(state, action) throws ArgumentNullException when action is null. The immediate scheduler runs the action synchronously on the calling thread, and since there is no queue, it validates the delegate at the very start.","triggerScenarios":"Calling Scheduler.Immediate.Schedule(state, null), or an Rx operator/timer helper (e.g. via InvokeRec, ScheduleAsync) receiving a null delegate and forwarding it to the immediate scheduler.","commonSituations":"Unit tests exercising Rx operators with hand-written schedulers; code paths where a lambda is built from a nullable callback and immediately executed synchronously via Immediate.","solutions":["Pass a non-null delegate to Schedule; trace the null back to the lambda/field that was never assigned.","Validate delegates at your API boundary before invoking Rx scheduling.","Use a fallback no-op action if executing nothing is acceptable: (s, st) => Disposable.Empty."],"exampleFix":"// before\nAction? userCallback = maybeNull;\nScheduler.Immediate.Schedule(0, (s, st) => { userCallback!(); return Disposable.Empty; }); // throws if userCallback null\n\n// after\nif (userCallback != null)\n    Scheduler.Immediate.Schedule(0, (s, st) => { userCallback(); return Disposable.Empty; });","handlingStrategy":"validation","validationCode":"if (action is null) return Disposable.Empty; // or throw earlier with context\nScheduler.Immediate.Schedule(state, action);","typeGuard":"static bool HasAction<TState>(Func<IScheduler, TState, IDisposable>? a) => a is not null;","tryCatchPattern":"try { Scheduler.Immediate.Schedule(state, action); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"action\")\n{\n    // delegate was null upstream\n}","preventionTips":["Null-check user callbacks at your API boundary","Prefer optional-callback patterns over nullable Funcs","Run Rx operator tests with fully initialized delegates"],"tags":["null-argument","scheduler","immediate"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}