{"record":{"id":"5f450aa04138e446","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-5f450a","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive.Uwp/System.Reactive.Linq/DependencyObjectObservable.cs","lineNumber":34,"sourceCode":"    /// <summary>\n    /// Rx extension methods for UWP's (Windows.UI.Xaml) <see cref=\"DependencyObject\"/>.\n    /// </summary>\n    [CLSCompliant(false)]\n    public static class DependencyObjectObservable\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        /// <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>","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive.Uwp/System.Reactive.Linq/DependencyObjectObservable.cs#L16-L52","documentation":"The UWP ObserveOn extension requires a non-null source observable; passing null throws ArgumentNullException('source'). Rx guards argument nulls eagerly at the operator call site so the failure happens immediately rather than inside the subscription pipeline.","triggerScenarios":"Calling source.ObserveOn(dependencyObject) (System.Reactive.Uwp DependencyObjectObservable, line 34) where the IObservable<TSource> argument is null.","commonSituations":"A factory method or property returning null observable, a nullable field not yet initialized, or a method chain where an earlier operator returned null instead of an empty sequence.","solutions":["Check why the source observable is null before calling ObserveOn; initialize or assign it (e.g. Observable.Empty<TSource>() as a safe default).","Add a null/has-value check on the variable producing the source sequence.","If the source comes from an event or property, ensure the publisher actually assigned the observable before the UI subscription runs."],"exampleFix":"// before\nIObservable<int> source = GetSource(); // may return null\nvar obs = source.ObserveOn(myControl);\n// after\nvar src = GetSource() ?? Observable.Empty<int>();\nvar obs = src.ObserveOn(myControl);","handlingStrategy":"validation","validationCode":"if (source == null) source = Observable.Empty<TSource>();\nvar obs = source.ObserveOn(dependencyObject);","typeGuard":"static IObservable<T> NotNull<T>(IObservable<T> s) => s ?? Observable.Empty<T>();","tryCatchPattern":"try\n{\n    var obs = source.ObserveOn(dependencyObject);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{\n    // fall back to empty/default sequence\n}","preventionTips":["Never let factory methods return null observables; return Observable.Empty<T>() or Observable.Never<T>().","Initialize observable fields at declaration or in the constructor.","Enable nullable reference types (C# 8+) so null sources are caught at compile time."],"tags":["rx","uwp","null-argument","observable"],"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"}