{"record":{"id":"67dac0f40d21a187","repo":"dotnet/reactive","slug":"action-parameter-action-scheduleditem","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/ScheduledItem.cs","lineNumber":187,"sourceCode":"        private readonly IScheduler _scheduler;\n        private readonly TValue _state;\n        private readonly Func<IScheduler, TValue, IDisposable> _action;\n\n        /// <summary>\n        /// Creates a materialized work item.\n        /// </summary>\n        /// <param name=\"scheduler\">Recursive scheduler to invoke the scheduled action with.</param>\n        /// <param name=\"state\">State to pass to the scheduled action.</param>\n        /// <param name=\"action\">Scheduled action.</param>\n        /// <param name=\"dueTime\">Time at which to run the scheduled action.</param>\n        /// <param name=\"comparer\">Comparer used to compare work items based on their scheduled time.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"scheduler\"/> or <paramref name=\"action\"/> or <paramref name=\"comparer\"/> is <c>null</c>.</exception>\n        public ScheduledItem(IScheduler scheduler, TValue state, Func<IScheduler, TValue, IDisposable> action, TAbsolute dueTime, IComparer<TAbsolute> comparer)\n            : base(dueTime, comparer)\n        {\n            _scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));\n            _state = state;\n            _action = action ?? throw new ArgumentNullException(nameof(action));\n        }\n\n        /// <summary>\n        /// Creates a materialized work item.\n        /// </summary>\n        /// <param name=\"scheduler\">Recursive scheduler to invoke the scheduled action with.</param>\n        /// <param name=\"state\">State to pass to the scheduled action.</param>\n        /// <param name=\"action\">Scheduled action.</param>\n        /// <param name=\"dueTime\">Time at which to run the scheduled action.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"scheduler\"/> or <paramref name=\"action\"/> is <c>null</c>.</exception>\n        public ScheduledItem(IScheduler scheduler, TValue state, Func<IScheduler, TValue, IDisposable> action, TAbsolute dueTime)\n            : this(scheduler, state, action, dueTime, Comparer<TAbsolute>.Default)\n        {\n        }\n\n        /// <summary>\n        /// Invokes the scheduled action with the supplied recursive scheduler and state.\n        /// </summary>","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Concurrency/ScheduledItem.cs#L169-L205","documentation":"The same ScheduledItem<TAbsolute, TValue> constructor throws ArgumentNullException when the action argument is null. The action (Func<IScheduler, TValue, IDisposable>) is invoked when the item becomes due; without it the scheduler would invoke a null delegate when the queue is drained.","triggerScenarios":"Constructing ScheduledItem with a null Func<IScheduler, TValue, IDisposable>, often from generic scheduling helpers that pass through user-provided lambdas without validation.","commonSituations":"Custom scheduler implementations re-implementing Schedule internally; test fakes building materialized work items; refactoring where a lambda was replaced by a null-returning factory method.","solutions":["Ensure a non-null action delegate is supplied; use '(_, __) => Disposable.Empty' for no-op items.","Validate the action in your wrapper before constructing the ScheduledItem.","Trace the scheduling call chain (Enqueue/Invoke paths) to find where the null originates.","Prefer building items via IScheduler.Schedule extension methods, which validate arguments."],"exampleFix":"// before\nvar item = new ScheduledItem<DateTimeOffset, int>(scheduler, state, action /* null */, dueTime, comparer);\n// after\nif (action == null) throw new ArgumentNullException(nameof(action));\nvar item = new ScheduledItem<DateTimeOffset, int>(scheduler, state, action, dueTime, comparer);","handlingStrategy":"validation","validationCode":"if (action == null)\n    throw new ArgumentNullException(nameof(action));","typeGuard":"bool HasAction<TValue>(Func<IScheduler, TValue, IDisposable> action) => action is not null;","tryCatchPattern":"try\n{\n    var item = new ScheduledItem<DateTimeOffset, TState>(scheduler, state, action, dueTime, comparer);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"action\")\n{\n    var item = new ScheduledItem<DateTimeOffset, TState>(scheduler, state, (_, __) => Disposable.Empty, dueTime, comparer);\n}","preventionTips":["Validate delegates before constructing materialized work items.","Use '(_, __) => Disposable.Empty' as a no-op item action.","Prefer IScheduler.Schedule extensions, which validate arguments, over direct ScheduledItem construction."],"tags":["rx","scheduler","argument-null","csharp"],"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"}