{"record":{"id":"c428018e43bd9742","repo":"dotnet/reactive","slug":"control","errorCode":null,"errorMessage":"control","messagePattern":"control","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Linq/ControlObservable.cs","lineNumber":36,"sourceCode":"        /// <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>\n        public static IObservable<TSource> ObserveOn<TSource>(this IObservable<TSource> source, Control control)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Linq/ControlObservable.cs#L18-L54","documentation":"The second validation in ControlObservable.SubscribeOn throws ArgumentNullException with parameter name 'control' when the Windows Forms Control is null. The control is required to build the ControlScheduler that marshals subscription to the UI thread.","triggerScenarios":"Calling source.SubscribeOn(null), typically when a control field/property is null because InitializeComponent has not run, the control was disposed, or a FindControl lookup failed.","commonSituations":"Code executing before the form's constructor finishes; controls removed from the layout and set to null; designer field renames leaving stale null references; unit tests without a real control.","solutions":["Pass a valid non-null Control instance.","Ensure InitializeComponent has run and the control reference is assigned before subscribing.","If the control may be absent, skip the SubscribeOn call or fall back to a different scheduler."],"exampleFix":"// before\nvar sub = source.SubscribeOn(this.statusStrip1); // statusStrip1 is null\n// after\nif (this.statusStrip1 != null)\n    var sub = source.SubscribeOn(this.statusStrip1);","handlingStrategy":"validation","validationCode":"if (control == null || control.IsDisposed)\n    throw new InvalidOperationException(\"Target control unavailable\");\nvar sub = source.SubscribeOn(control);","typeGuard":"static bool IsUsable(Control c) => c is { IsDisposed: false, IsHandleCreated: true };","tryCatchPattern":"try { var sub = source.SubscribeOn(control); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"control\") { log.Error(\"Control was null at SubscribeOn\"); }","preventionTips":["Check control.IsDisposed before marshaling to a control","Never cache control references across form lifetimes","Verify designer-generated fields exist after renaming controls"],"tags":["argument-null","winforms","rxjs","ui-thread"],"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"}