{"record":{"id":"7f68aadf438d152f","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-action-7f68aa","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'action')","messagePattern":"Value cannot be null\\. \\(Parameter 'action'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive.Wpf/System.Reactive.Concurrency/DispatcherScheduler.cs","lineNumber":87,"sourceCode":"\n        /// <summary>\n        /// Gets the priority at which work items will be dispatched.\n        /// </summary>\n        public System.Windows.Threading.DispatcherPriority Priority { get; }\n\n        /// <summary>\n        /// Schedules an action to be executed on the dispatcher.\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 <c>null</c>.</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            var d = new SingleAssignmentDisposable();\n\n            Dispatcher.BeginInvoke(\n                new Action(() =>\n                {\n                    if (!d.IsDisposed)\n                    {\n                        d.Disposable = action(this, state);\n                    }\n                }),\n                Priority\n            );\n\n            return d;\n        }\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive.Wpf/System.Reactive.Concurrency/DispatcherScheduler.cs#L69-L105","documentation":"DispatcherScheduler.Schedule<TState>(state, action) throws ArgumentNullException when the action delegate is null. The action is what gets BeginInvoke'd on the Dispatcher; there is nothing meaningful to schedule without it.","triggerScenarios":"Calling scheduler.Schedule(state, null) directly, or passing a null action into Schedule(TimeSpan)/Schedule(DateTimeOffset) overloads that forward to this method (they null-check the forwarded delegate).","commonSituations":"Building a scheduling pipeline where the work delegate is produced dynamically and can be null; IScheduler abstraction code passing through a null action from an upstream operator; tests verifying argument checking (Schedule_ArgumentChecking).","solutions":["Ensure a non-null Func<IScheduler, TState, IDisposable> is passed to Schedule.","If the work may be absent, schedule a no-op: (scheduler, state) => Disposable.Empty.","Check any wrapper around IScheduler so it propagates real delegates rather than null."],"exampleFix":"// before\nscheduler.Schedule(state, null);\n// after\nscheduler.Schedule(state, (sched, st) => { DoWork(st); return Disposable.Empty; });","handlingStrategy":"validation","validationCode":"if (action == null) throw new InvalidOperationException(\"schedule action required\");","typeGuard":"bool HasAction<TState>(Func<IScheduler, TState, IDisposable> a) => a is not null;","tryCatchPattern":"try { scheduler.Schedule(state, action); } catch (ArgumentNullException ex) when (ex.ParamName == \"action\") { /* fix delegate */ }","preventionTips":["Return Disposable.Empty no-op lambdas instead of null for empty work.","Keep delegates in non-nullable fields/parameters.","Wrap IScheduler usage in a helper that asserts non-null actions once."],"tags":["wpf","scheduler","null-argument","dispatch"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}