{"record":{"id":"8c69403110c21a96","repo":"dotnet/reactive","slug":"source-coredispatcherobservable","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/CoreDispatcherObservable.cs","lineNumber":147,"sourceCode":"                throw new ArgumentNullException(nameof(source));\n            }\n\n            return Synchronization.ObserveOn(source, CoreDispatcherScheduler.Current);\n        }\n\n        /// <summary>\n        /// Wraps the source sequence in order to run its observer callbacks on the dispatcher associated with the current window.\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=\"priority\">Priority to schedule work items at.</param>\n        /// <returns>The source sequence whose observations happen on the current window's dispatcher.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        public static IObservable<TSource> ObserveOnDispatcher<TSource>(this IObservable<TSource> source, CoreDispatcherPriority priority)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            return Synchronization.ObserveOn(source, new CoreDispatcherScheduler(CoreDispatcherScheduler.Current.Dispatcher, priority));\n        }\n\n        #endregion\n\n        #region SubscribeOn[CoreDispatcher]\n\n        /// <summary>\n        /// Wraps the source sequence in order to run its subscription and unsubscription logic on the specified dispatcher.\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=\"dispatcher\">Dispatcher whose associated message loop is used to perform subscription and unsubscription actions on.</param>\n        /// <returns>The source sequence whose subscriptions and unsubscriptions happen on the specified dispatcher.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"dispatcher\"/> is null.</exception>\n        /// <remarks>","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/CoreDispatcherObservable.cs#L129-L165","documentation":"ObserveOnDispatcher(source, priority) throws ArgumentNullException when the source sequence is null. The method builds a CoreDispatcherScheduler from CoreDispatcherScheduler.Current.Dispatcher with the given priority and passes the source to Synchronization.ObserveOn; it rejects a null source up front. This follows Rx's convention of eagerly validating arguments so failures point at the calling code.","triggerScenarios":"Invoking the extension on a null IObservable<T>, typically because an upstream factory/property returned null or a conditionally-built chain assigned null to the sequence variable.","commonSituations":"View-models exposing IObservable properties that are null until initialization completes; service locators returning null instead of throwing; fluent chains assembled from nullable data sources.","solutions":["Make the producer return Observable.Empty<T>() or Observable.Throw<T>(ex) instead of null.","Guard the chain with a null check before applying ObserveOnDispatcher.","Initialize the observable field eagerly (constructor or field initializer) so it is never null when the pipeline is built.","Prefer ObserveOnCoreDispatcher() when no custom priority is needed — the validation behavior is identical but the API is simpler."],"exampleFix":"// before\nIObservable<EventData> stream = _events; // null until Init()\nstream.ObserveOnDispatcher(CoreDispatcherPriority.High).Subscribe(...);\n// after\nif (stream == null) stream = Observable.Empty<EventData>();\nstream.ObserveOnDispatcher(CoreDispatcherPriority.High).Subscribe(...);","handlingStrategy":"validation","validationCode":"if (source == null) throw new InvalidOperationException(\"source sequence not initialized\");\nsource.ObserveOnDispatcher(CoreDispatcherPriority.Normal).Subscribe(handler);","typeGuard":"bool IsSubscribable<T>(IObservable<T> s) => s != null;","tryCatchPattern":"try { source.ObserveOnDispatcher(priority).Subscribe(handler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{ logger.LogWarning(\"Observable pipeline skipped: source was null\"); }","preventionTips":["Never assign null to IObservable fields; default to Observable.Empty<T>().","Build pipelines after async initialization completes (await before composing).","Use code contracts or Debug.Assert(source != null) at pipeline construction sites.","Prefer ObserveOnCoreDispatcher() when a custom priority isn't needed."],"tags":["argumentnull","winrt","reactive-extensions","null-source","dispatcher"],"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"}