{"record":{"id":"ce886336573edfab","repo":"dotnet/reactive","slug":"action-coredispatcherscheduler","errorCode":null,"errorMessage":"action","messagePattern":"action","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Concurrency/CoreDispatcherScheduler.cs","lineNumber":83,"sourceCode":"\n        /// <summary>\n        /// Gets the priority at which work is scheduled.\n        /// </summary>\n        public CoreDispatcherPriority 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            var res = Dispatcher.RunAsync(Priority, () =>\n            {\n                if (!d.IsDisposed)\n                {\n                    try\n                    {\n                        d.Disposable = action(this, state);\n                    }\n                    catch (Exception ex)\n                    {\n                        //\n                        // Work-around for the behavior of throwing from RunAsync not propagating\n                        // the exception to the Application.UnhandledException event (as of W8RP)\n                        // as our users have come to expect from previous XAML stacks using Rx.","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Concurrency/CoreDispatcherScheduler.cs#L65-L101","documentation":"CoreDispatcherScheduler.Schedule<TState> throws ArgumentNullException when the action delegate is null. The delegate is what gets queued on the CoreDispatcher via RunAsync; a null delegate cannot be dispatched, so Rx validates before creating the SingleAssignmentDisposable and invoking RunAsync.","triggerScenarios":"Calling scheduler.Schedule(state, null) or Schedule((s, st) => null-literal delegate); also occurs when a computed delegate variable is null due to failed conditional logic.","commonSituations":"Generic scheduling helpers that build the action dynamically and pass an unset delegate; wrapper code around IScheduler that forwards arguments without validation.","solutions":["Pass a valid Func<IScheduler, TState, IDisposable>; return Disposable.Empty for no-op work.","Null-check the delegate before scheduling when it is computed at runtime.","If using Schedule(state, action) overloads, ensure the lambda's body returns an IDisposable."],"exampleFix":"// before\nFunc<IScheduler, int, IDisposable> work = null;\nsched.Schedule(0, work); // ANE\n// after\nvar sched2 = sched.Schedule(0, work ?? ((s, st) => Disposable.Empty));","handlingStrategy":"validation","validationCode":"if (action == null) throw new InvalidOperationException(\"schedule action must not be null\");","typeGuard":"bool Schedulable<TState>(Func<IScheduler, TState, IDisposable> a) => a is not null;","tryCatchPattern":"try { sched.Schedule(state, action); } catch (ArgumentNullException ex) when (ex.ParamName == \"action\") { /* skip or log no-op */ }","preventionTips":["Default no-op work to Disposable.Empty-returning lambdas","Null-check computed delegates before scheduling","Wrap scheduler calls in helpers that validate arguments once"],"tags":["dotnet","rx","uwp","argument-null","scheduler"],"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"}