{"record":{"id":"d4d0d6a1698e8d35","repo":"dotnet/reactive","slug":"scheduler-value-cannot-be-null","errorCode":null,"errorMessage":"scheduler (Value cannot be null)","messagePattern":"scheduler \\(Value cannot be null\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs","lineNumber":381,"sourceCode":"\n            return ScheduleAsync_(scheduler, state, dueTime, action);\n        }\n\n        /// <summary>\n        /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.\n        /// </summary>\n        /// <typeparam name=\"TState\">The type of the state passed to the scheduled action.</typeparam>\n        /// <param name=\"scheduler\">Scheduler to schedule work on.</param>\n        /// <param name=\"state\">State to pass to the asynchronous method.</param>\n        /// <param name=\"dueTime\">Absolute time at which to execute the action.</param>\n        /// <param name=\"action\">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>\n        /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"scheduler\"/> or <paramref name=\"action\"/> is <c>null</c>.</exception>\n        public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> 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 ScheduleAsync_(scheduler, state, dueTime, action);\n        }\n\n        /// <summary>\n        /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.\n        /// </summary>\n        /// <param name=\"scheduler\">Scheduler to schedule work on.</param>\n        /// <param name=\"dueTime\">Absolute time at which to execute the action.</param>\n        /// <param name=\"action\">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>\n        /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"scheduler\"/> or <paramref name=\"action\"/> is <c>null</c>.</exception>","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs#L363-L399","documentation":"System.Reactive's ScheduleAsync extension requires a non-null IScheduler receiver. Passing null causes an ArgumentNullException with message \"Value cannot be null (Parameter 'scheduler')\". The library validates up front so no scheduling machinery is initialized for an invalid call.","triggerScenarios":"Calling scheduler.ScheduleAsync<TState>(state, dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action) on a null IScheduler receiver — legal syntax because it is a C# extension method.","commonSituations":"DI-resolved scheduler was not registered and injected as null; a custom scheduler factory returned null; scheduler variable captured before initialization.","solutions":["Use a concrete scheduler instance such as Scheduler.Default, TaskPoolScheduler.Default, or NewThreadScheduler.Default.","Null-check the scheduler before calling and substitute Scheduler.Default when absent.","Correct the DI registration or factory that yields the null scheduler."],"exampleFix":"// before\nIScheduler scheduler = null;\nscheduler.ScheduleAsync(state, dueTime, action); // throws\n// after\nvar scheduler = Scheduler.Default;\nscheduler.ScheduleAsync(state, dueTime, action);","handlingStrategy":"validation","validationCode":"if (scheduler == null) scheduler = Scheduler.Default;","typeGuard":"bool HasScheduler(IScheduler s) => s is not null;","tryCatchPattern":"try { disposable = scheduler.ScheduleAsync(state, dueTime, action); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"scheduler\") { disposable = Scheduler.Default.ScheduleAsync(state, dueTime, action); }","preventionTips":["Prefer `var sched = injectedScheduler ?? Scheduler.Default;` before scheduling.","Register IScheduler in the DI container to guarantee a non-null injection.","Do not rely on the compiler to catch null extension-method receivers."],"tags":["rx","scheduler","null-argument","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"}