{"record":{"id":"97edcce5d8ac5f88","repo":"dotnet/reactive","slug":"dispatcherobject","errorCode":null,"errorMessage":"dispatcherObject","messagePattern":"dispatcherObject","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Linq/DispatcherObservable.cs","lineNumber":106,"sourceCode":"\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            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (dispatcherObject == null)\n            {\n                throw new ArgumentNullException(nameof(dispatcherObject));\n            }\n\n            return ObserveOn_(source, dispatcherObject.Dispatcher);\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        /// <param name=\"priority\">Priority to schedule work items at.</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, DispatcherPriority priority)\n        {\n            if (source == null)\n            {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Linq/DispatcherObservable.cs#L88-L124","documentation":"Thrown by ObserveOn(source, DispatcherObject) when the DispatcherObject argument is null. The operator calls dispatcherObject.Dispatcher to find the scheduling target; a null object provides no dispatcher, so it throws ArgumentNullException('dispatcherObject').","triggerScenarios":"Passing a null Window/Control/UserControl reference (e.g. a closed and cleared window reference, or a control accessed before InitializeComponent completed).","commonSituations":"Holding weak references to views that were garbage collected or set to null on navigation, and still using them to schedule UI updates from background observables.","solutions":["Pass a live UI element (e.g. an initialized Window or Control)","Use Application.Current.Dispatcher directly when the specific element is gone","Check that the view was constructed (InitializeComponent called) before scheduling onto it"],"exampleFix":"// before\nWindow target = _window; // null after close\nstream.ObserveOn(target);\n// after\nstream.ObserveOn(Application.Current.Dispatcher);","handlingStrategy":"validation","validationCode":"var dispatcher = dispatcherObject?.Dispatcher ?? Application.Current?.Dispatcher ?? throw new InvalidOperationException(\"No dispatcher available\");","typeGuard":"bool CanSchedule(DispatcherObject o) => o is not null && o.Dispatcher is not null;","tryCatchPattern":"try { stream.ObserveOn(view).Subscribe(...); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"dispatcherObject\") { stream.ObserveOn(Application.Current.Dispatcher).Subscribe(...); }","preventionTips":["Prefer Application.Current.Dispatcher over per-view dispatchers for long-lived subscriptions","Check view liveness (IsLoaded) before scheduling onto a control","Keep a strong reference to the view while subscriptions are active"],"tags":["csharp","null-argument","rx","wpf"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}