{"record":{"id":"8389f1dde1debe7e","repo":"dotnet/reactive","slug":"scheduler-observable-imperative","errorCode":null,"errorMessage":"scheduler","messagePattern":"scheduler","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Imperative.cs","lineNumber":176,"sourceCode":"        /// <param name=\"scheduler\">Scheduler to generate an empty sequence on in case no matching source in <paramref name=\"sources\"/> is found.</param>\n        /// <returns>The observable sequence retrieved from the <paramref name=\"sources\"/> dictionary based on the <paramref name=\"selector\"/> invocation result, or an empty sequence if no match is found.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"selector\"/> or <paramref name=\"sources\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        public static IObservable<TResult> Case<TValue, TResult>(Func<TValue> selector, IDictionary<TValue, IObservable<TResult>> sources, IScheduler scheduler)\n            where TValue : notnull\n        {\n            if (selector == null)\n            {\n                throw new ArgumentNullException(nameof(selector));\n            }\n\n            if (sources == null)\n            {\n                throw new ArgumentNullException(nameof(sources));\n            }\n\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return s_impl.Case(selector, sources, scheduler);\n        }\n\n        /// <summary>\n        /// Uses <paramref name=\"selector\"/> to determine which source in <paramref name=\"sources\"/> to return, choosing an empty sequence if no match is found.\n        /// </summary>\n        /// <typeparam name=\"TValue\">The type of the value returned by the selector function, used to look up the resulting source.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence.</typeparam>\n        /// <param name=\"selector\">Selector function invoked to determine the source to lookup in the <paramref name=\"sources\"/> dictionary.</param>\n        /// <param name=\"sources\">Dictionary of sources to select from based on the <paramref name=\"selector\"/> invocation result.</param>\n        /// <returns>The observable sequence retrieved from the <paramref name=\"sources\"/> dictionary based on the <paramref name=\"selector\"/> invocation result, or an empty sequence if no match is found.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"selector\"/> or <paramref name=\"sources\"/> is null.</exception>\n        public static IObservable<TResult> Case<TValue, TResult>(Func<TValue> selector, IDictionary<TValue, IObservable<TResult>> sources)\n            where TValue : notnull\n        {\n            if (selector == null)","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Imperative.cs#L158-L194","documentation":"The Case(selector, sources, scheduler) overload throws ArgumentNullException when the IScheduler is null. The scheduler controls which context the default branch (Observable.Empty) is subscribed on, and this overload requires an explicit one, rejected at Observable.Imperative.cs:176.","triggerScenarios":"Calling Observable.Case(selector, sources, scheduler) with a null IScheduler, e.g. a scheduler resolved from config or DI that was not registered.","commonSituations":"Scheduler injected via constructor left uninitialized; passing a null scheduler in unit tests; a resolution helper returning null when the scheduler name is unknown.","solutions":["Pass a concrete scheduler such as Scheduler.Default, Scheduler.Immediate, or Scheduler.CurrentThread.","Fix the DI/config resolution that was supposed to supply the IScheduler.","Use Scheduler.Default as a fallback when a resolved scheduler is null."],"exampleFix":"// before\nvar sched = _schedulers.GetValueOrDefault(name); // null if name unknown\nObservable.Case(selector, sources, sched);\n// after\nvar sched = _schedulers.GetValueOrDefault(name) ?? Scheduler.Default;\nObservable.Case(selector, sources, sched);","handlingStrategy":"validation","validationCode":"if (scheduler is null) throw new ArgumentNullException(nameof(scheduler));\nvar result = Observable.Case(selector, sources, scheduler);","typeGuard":null,"tryCatchPattern":"try { var q = Observable.Case(selector, sources, scheduler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"scheduler\") { /* fall back to Scheduler.Default */ }","preventionTips":["Resolve schedulers from Scheduler.Default/Immediate/CurrentThread rather than nullable injection points.","Validate scheduler configuration at startup.","Use ?? Scheduler.Default wherever a scheduler comes from an optional source."],"tags":["argumentnull","reactive-extensions","scheduler","case-operator"],"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"}