{"record":{"id":"90d18f112c910ece","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-scheduler-90d18f","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'scheduler')","messagePattern":"Value cannot be null\\. \\(Parameter 'scheduler'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive.Wpf/System.Reactive.Linq/DispatcherObservable.cs","lineNumber":86,"sourceCode":"\n        /// <summary>\n        /// Wraps the source sequence in order to run its observer callbacks on the specified dispatcher scheduler.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"scheduler\">Dispatcher scheduler to notify observers on.</param>\n        /// <returns>The source sequence whose observations happen on the specified dispatcher scheduler.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        public static IObservable<TSource> ObserveOn<TSource>(this IObservable<TSource> source, DispatcherScheduler scheduler)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return ObserveOn_(source, scheduler.Dispatcher, scheduler.Priority);\n        }\n\n\n        /// <summary>\n        /// Wraps the source sequence in order to run its observer callbacks on the dispatcher associated with the specified object.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"dispatcherObject\">Object to get the dispatcher from.</param>\n        /// <returns>The source sequence whose observations happen on the specified object's dispatcher.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"dispatcherObject\"/> is null.</exception>\n        public static IObservable<TSource> ObserveOn<TSource>(this IObservable<TSource> source, DispatcherObject dispatcherObject)\n        {\n            if (source == null)\n            {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive.Wpf/System.Reactive.Linq/DispatcherObservable.cs#L68-L104","documentation":"This ObserveOn overload requires a non-null DispatcherScheduler instance; it throws ArgumentNullException('scheduler') when null. The scheduler's Dispatcher and Priority are read immediately (scheduler.Dispatcher, scheduler.Priority), so a null wrapper cannot be tolerated.","triggerScenarios":"Calling source.ObserveOn(dispatcherScheduler) where the DispatcherScheduler was never created or was injected/looked up as null, e.g., new DispatcherScheduler not yet assigned, or a container returning null for the scheduler registration.","commonSituations":"DI registration missing for DispatcherScheduler; creating the scheduler lazily on a background thread; accessing a static scheduler singleton before WPF application initialization.","solutions":["Create the DispatcherScheduler explicitly from a valid Dispatcher: new DispatcherScheduler(Dispatcher.CurrentDispatcher).","Verify the DI container registration provides a DispatcherScheduler and that resolution succeeded before calling ObserveOn.","If the scheduler is optional in some hosts, branch: use the DispatcherScheduler overload only when available, otherwise a standard IScheduler overload."],"exampleFix":"// before\nDispatcherScheduler sched = _schedulerProvider.Get(); // may return null\nvar ui = source.ObserveOn(sched);\n// after\nvar sched = _schedulerProvider.Get() ?? new DispatcherScheduler(Application.Current.Dispatcher);\nvar ui = source.ObserveOn(sched);","handlingStrategy":"validation","validationCode":"if (dispatcherScheduler == null) dispatcherScheduler = new DispatcherScheduler(Application.Current.Dispatcher);","typeGuard":"bool schedulerReady = dispatcherScheduler != null && dispatcherScheduler.Dispatcher != null;","tryCatchPattern":"try { var ui = source.ObserveOn(dispatcherScheduler); } catch (ArgumentNullException ex) when (ex.ParamName == \"scheduler\") { var ui = source.ObserveOn(Scheduler.Default); }","preventionTips":["Register DispatcherScheduler explicitly in the DI container.","Create the scheduler on the UI thread so its Dispatcher is valid.","Fall back to Dispatcher.CurrentDispatcher when no wrapper is configured."],"tags":["null-argument","wpf","scheduler","reactive-extensions"],"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"}