{"record":{"id":"b65db6b99a903d04","repo":"dotnet/reactive","slug":"scheduler-observable-binding","errorCode":null,"errorMessage":"scheduler","messagePattern":"scheduler","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs","lineNumber":283,"sourceCode":"        /// <summary>\n        /// Returns an observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Connectable observable sequence.</param>\n        /// <param name=\"disconnectDelay\">The time span that should be waited before possibly unsubscribing from the connectable observable.</param>\n        /// <param name=\"scheduler\">The scheduler to use for delayed unsubscription.</param>\n        /// <returns>An observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        public static IObservable<TSource> RefCount<TSource>(this IConnectableObservable<TSource> source, TimeSpan disconnectDelay, IScheduler scheduler)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            if (disconnectDelay < TimeSpan.Zero)\n            {\n                throw new ArgumentException(\"Delay cannot be less than zero\", nameof(disconnectDelay));\n            }\n\n            return s_impl.RefCount(source, disconnectDelay, scheduler);\n        }\n\n        /// <summary>\n        /// Returns an observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Connectable observable sequence.</param>\n        /// <param name=\"minObservers\">The minimum number of observers required to subscribe before establishing the connection to the source.</param>\n        /// <returns>An observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs#L265-L301","documentation":"RefCount stays connected while subscriptions exist and uses the scheduler to honor disconnectDelay; a null scheduler leaves the delayed unsubscribe undefined. The parameter name in the message is 'scheduler'. Fix: pass a non-null IScheduler.","triggerScenarios":"Calling the scheduler overload with a null scheduler, e.g. an uninitialized scheduler field, a TestScheduler variable not yet assigned, or a DI-resolved scheduler that was null.","commonSituations":"Unit tests forgetting to instantiate the TestScheduler, configuration-driven scheduler selection returning null, or refactors removing Scheduler.Default.","solutions":["Pass an explicit scheduler such as Scheduler.Default or Scheduler.ThreadPool","Initialize the scheduler variable/DI binding before calling RefCount","In tests, create the TestScheduler before using it"],"exampleFix":"// before\nIScheduler sched = null;\nvar obs = conn.RefCount(TimeSpan.FromSeconds(1), sched);\n// after\nvar obs = conn.RefCount(TimeSpan.FromSeconds(1), Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (scheduler == null) scheduler = Scheduler.Default;","typeGuard":null,"tryCatchPattern":"try { var obs = conn.RefCount(delay, sched); } catch (ArgumentNullException ex) when (ex.ParamName == \"scheduler\") { sched = Scheduler.Default; }","preventionTips":["Default optional scheduler parameters to Scheduler.Default, not null","Initialize TestScheduler instances before use in tests","Validate DI-resolved IScheduler bindings at startup"],"tags":["argument-null","reactive-extensions","scheduler"],"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"}