{"record":{"id":"3666d37a360ff60f","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-dependencyobject","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'dependencyObject')","messagePattern":"Value cannot be null\\. \\(Parameter 'dependencyObject'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive.Uwp/System.Reactive.Linq/DependencyObjectObservable.cs","lineNumber":39,"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=\"dependencyObject\">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=\"dependencyObject\"/> is null.</exception>\n        public static IObservable<TSource> ObserveOn<TSource>(this IObservable<TSource> source, DependencyObject dependencyObject)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (dependencyObject == null)\n            {\n                throw new ArgumentNullException(nameof(dependencyObject));\n            }\n\n            return Synchronization.ObserveOn(source, new CoreDispatcherScheduler(dependencyObject.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=\"dependencyObject\">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=\"dependencyObject\"/> is null.</exception>\n        public static IObservable<TSource> ObserveOn<TSource>(this IObservable<TSource> source, DependencyObject dependencyObject, CoreDispatcherPriority priority)\n        {\n            if (source == null)\n            {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive.Uwp/System.Reactive.Linq/DependencyObjectObservable.cs#L21-L57","documentation":"The UWP ObserveOn extension requires a non-null DependencyObject; passing null throws ArgumentNullException('dependencyObject'). The dependencyObject supplies the CoreDispatcher that observations will be marshalled to, so a null target has no valid scheduling destination.","triggerScenarios":"Calling source.ObserveOn(null) (DependencyObjectObservable, line 39), e.g. a UI control or page reference that is null when the subscription is set up.","commonSituations":"Accessing a control before InitializeComponent / page Loaded, a DataContext-bound element not yet materialized, or code running before the XAML visual tree is built.","solutions":["Pass a valid DependencyObject (the page, control, or window) and defer the ObserveOn call until the control exists (e.g. in OnNavigatedTo or Loaded event).","Guard with a null check before subscribing and skip or log when no UI target is available.","Verify bindings/FindName actually resolved the control instead of returning null."],"exampleFix":"// before\nsource.ObserveOn((DependencyObject)null);\n// after\nif (myControl != null)\n{\n    source.ObserveOn(myControl);\n}","handlingStrategy":"validation","validationCode":"if (dependencyObject != null)\n{\n    var obs = source.ObserveOn(dependencyObject);\n}","typeGuard":"static bool HasUiTarget(DependencyObject d) => d is not null;","tryCatchPattern":"try\n{\n    var obs = source.ObserveOn(dependencyObject);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"dependencyObject\")\n{\n    // defer or skip UI-marshalled subscription\n}","preventionTips":["Subscribe only after the page/control exists (OnNavigatedTo, Loaded).","Check FindName/binding results for null before using them as UI targets.","Keep references to UI elements in fields that are reset only after unsubscribing."],"tags":["rx","uwp","null-argument","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"}