{"record":{"id":"359c910a13d54f9e","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-controlobservable","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.Windows.Forms/System.Reactive.Linq/ControlObservable.cs","lineNumber":35,"sourceCode":"    public static class ControlObservable\n    {\n        /// <summary>\n        /// Wraps the source sequence in order to run its subscription and unsubscription logic on the Windows Forms message loop associated with the specified control.\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=\"control\">Windows Forms control whose associated message loop is used to perform subscription and unsubscription actions on.</param>\n        /// <returns>The source sequence whose subscriptions and unsubscriptions happen on the Windows Forms message loop associated with the specified control.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"control\"/> is null.</exception>\n        /// <remarks>\n        /// Only the side-effects of subscribing to the source sequence and disposing subscriptions to the source sequence are run on the specified control.\n        /// In order to invoke observer callbacks on the specified control, e.g. to render results in a control, use <see cref=\"ObserveOn\"/>.\n        /// </remarks>\n        public static IObservable<TSource> SubscribeOn<TSource>(this IObservable<TSource> source, Control control)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (control == null)\n            {\n                throw new ArgumentNullException(nameof(control));\n            }\n\n            return Synchronization.SubscribeOn(source, new ControlScheduler(control));\n        }\n\n        /// <summary>\n        /// Wraps the source sequence in order to run its observer callbacks on the Windows Forms message loop associated with the specified control.\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=\"control\">Windows Forms control whose associated message loop is used to notify observers on.</param>\n        /// <returns>The source sequence whose observations happen on the Windows Forms message loop associated with the specified control.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"control\"/> is null.</exception>","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive.Windows.Forms/System.Reactive.Linq/ControlObservable.cs#L17-L53","documentation":"ControlObservable.SubscribeOn throws ArgumentNullException when the source IObservable<TSource> is null. Extension methods on IObservable validate the receiver explicitly because a null 'this' does not throw on its own in C# extension-method calls. The scheduler-based subscribe redirection must not be built around a null sequence.","triggerScenarios":"Calling nullObservable.SubscribeOn(someControl) — typically when the observable came from a factory, service, or property that returned null.","commonSituations":"Chained Rx queries where an earlier operator or a lazy provider produced null instead of an empty/throwing sequence; dependency injection returning null for an observable service.","solutions":["Ensure the source observable is non-null before calling SubscribeOn.","If the source may be absent, guard with a null check or use Observable.Empty<TSource>() instead of null.","Fix the upstream factory/property so it never returns a null IObservable."],"exampleFix":"// before\nIObservable<Data> src = GetSource(); // returns null\nsrc.SubscribeOn(this.tabControl1).Subscribe(...);\n// after\nIObservable<Data> src = GetSource() ?? Observable.Empty<Data>();\nsrc.SubscribeOn(this.tabControl1).Subscribe(...);","handlingStrategy":"validation","validationCode":"if (source is null) throw new InvalidOperationException(\"source observable is null\");\nsource.SubscribeOn(control);","typeGuard":"bool HasSource<TSource>(IObservable<TSource> s) => s is not null;","tryCatchPattern":"try { source.SubscribeOn(control).Subscribe(obs); } catch (ArgumentNullException ex) when (ex.ParamName == \"source\") { Log(\"Source observable was null\"); }","preventionTips":["Never let factories return null IObservable; return Observable.Empty or Throw","Null-check the result of service/property lookups before Rx chaining","Enable nullable reference types to catch null observables at compile time"],"tags":["csharp","rx","argumentnull","winforms"],"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"}