{"record":{"id":"47cdec743be7ee92","repo":"dotnet/reactive","slug":"source-parameter-source-coredispatcherobservable","errorCode":null,"errorMessage":"source (Parameter 'source')","messagePattern":"source \\(Parameter 'source'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/CoreDispatcherObservable.cs","lineNumber":35,"sourceCode":"    /// </summary>\n    [CLSCompliant(false)]\n    public static class CoreDispatcherObservable\n    {\n        #region ObserveOn[CoreDispatcher]\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, CoreDispatcher 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 Synchronization.ObserveOn(source, new CoreDispatcherScheduler(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":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/CoreDispatcherObservable.cs#L17-L53","documentation":"The ObserveOn(CoreDispatcher) extension marshals observable notifications onto a WinRT CoreDispatcher; the source observable must be non-null. ArgumentNullException with ParamName 'source' is thrown by the first guard in the method. Without it, Synchronization.ObserveOn would fail later or produce a NullReferenceException on subscription.","triggerScenarios":"Calling someObservable.ObserveOn(dispatcher) where the receiver is null, e.g. an event stream property not yet initialized, or a service returning null instead of an empty sequence.","commonSituations":"Wiring UI bindings before the ViewModel's stream is created; timer/event-based streams that are null until started; unit tests forgetting to stub the observable.","solutions":["Verify the receiver observable is initialized before calling ObserveOn; use Observable.Empty<T>() or a Subject<T> instead of null.","Reorder initialization so the stream is created before UI marshalling is set up.","Wrap with a null-coalescing default: (source ?? Observable.Empty<T>()).ObserveOn(dispatcher)."],"exampleFix":"// before\nvar bound = vm.Stream.ObserveOn(dispatcher).Subscribe(OnNext); // vm.Stream may be null\n// after\nvar bound = (vm.Stream ?? Observable.Empty<Item>()).ObserveOn(dispatcher).Subscribe(OnNext);","handlingStrategy":"validation","validationCode":"if (source == null || dispatcher == null)\n    throw new InvalidOperationException(\"ObserveOn requires a non-null source and dispatcher\");","typeGuard":"bool CanObserveOn<TSource>(IObservable<TSource> s, CoreDispatcher d) => s is not null && d is not null;","tryCatchPattern":"try { subscription = stream.ObserveOn(dispatcher).Subscribe(onNext); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { subscription = Subscription.Empty; }","preventionTips":["Expose only non-null observables from view models.","Create streams during construction, before UI binding.","Null-coalesce with Observable.Empty<T>() at subscription sites."],"tags":["argument-null","winrt","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"}