{"record":{"id":"1abb3e717b22d15a","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-dispatcherobservable","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive.Wpf/System.Reactive.Linq/DispatcherObservable.cs","lineNumber":34,"sourceCode":"    /// Provides a set of extension methods for scheduling actions performed through observable sequences on UI dispatchers.\n    /// </summary>\n    public static class DispatcherObservable\n    {\n        #region ObserveOn[Dispatcher]\n\n        /// <summary>\n        /// Wraps the source sequence in order to run its observer callbacks 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 notify observers on.</param>\n        /// <returns>The source sequence whose observations happen on the specified dispatcher.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"dispatcher\"/> is null.</exception>\n        public static IObservable<TSource> ObserveOn<TSource>(this IObservable<TSource> source, Dispatcher dispatcher)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (dispatcher == null)\n            {\n                throw new ArgumentNullException(nameof(dispatcher));\n            }\n\n            return ObserveOn_(source, dispatcher);\n        }\n\n        /// <summary>\n        /// Wraps the source sequence in order to run its observer callbacks 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 notify observers on.</param>\n        /// <param name=\"priority\">Priority to schedule work items at.</param>\n        /// <returns>The source sequence whose observations happen on the specified dispatcher.</returns>","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive.Wpf/System.Reactive.Linq/DispatcherObservable.cs#L16-L52","documentation":"ObserveOn(source, dispatcher) requires a non-null source sequence to schedule on the WPF Dispatcher. The library eagerly validates arguments and throws ArgumentNullException when source is null, since it cannot wrap a null observable. This is a defensive contract check before constructing the internal ObserveOn_ pipeline.","triggerScenarios":"Calling Observable.ObserveOn(mySequence, dispatcher) where mySequence is a null IObservable<TSource> reference (e.g., an uninitialized field, a method returning null, or a failed lookup).","commonSituations":"Storing an observable in a field/property that was never assigned; a factory method returning null instead of Observable.Empty; refactoring away the producer of a sequence while UI code still subscribes; MVVM bindings wired before the source stream is created.","solutions":["Ensure the IObservable passed as source is initialized before calling ObserveOn (use Observable.Empty or a ReplaySubject placeholder instead of null).","Add a null check or assertion on the source sequence at the call site to fail early with a clearer message.","Refactor producers to never return null observables (return Observable.Empty<T>() or Deferred observables)."],"exampleFix":"// before\nIObservable<int> ticks = GetTicks(); // may return null\nvar onUi = ticks.ObserveOnDispatcher();\n// after\nIObservable<int> ticks = GetTicks() ?? Observable.Empty<int>();\nvar onUi = ticks.ObserveOn(dispatcher);","handlingStrategy":"validation","validationCode":"if (source == null) throw new InvalidOperationException(\"source sequence must be initialized before ObserveOn\");","typeGuard":"var safeSource = source ?? Observable.Empty<TSource>();","tryCatchPattern":"try { var ui = source.ObserveOn(dispatcher); } catch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* fall back to Observable.Empty */ }","preventionTips":["Never let factory methods return null observables; return Observable.Empty<T>().","Initialize observable fields inline or in constructors.","Run nullable reference types (C# 8 #nullable enable) to catch null sources at compile time."],"tags":["null-argument","wpf","reactive-extensions","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}