{"record":{"id":"46ef4594db2849e7","repo":"dotnet/reactive","slug":"selector-observable-imperative","errorCode":null,"errorMessage":"selector","messagePattern":"selector","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Imperative.cs","lineNumber":135,"sourceCode":"\n        #region + Case +\n\n        /// <summary>\n        /// Uses <paramref name=\"selector\"/> to determine which source in <paramref name=\"sources\"/> to return, choosing <paramref name=\"defaultSource\"/> 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        /// <param name=\"defaultSource\">Default source to select 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 <paramref name=\"defaultSource\"/> if no match is found.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"selector\"/> or <paramref name=\"sources\"/> or <paramref name=\"defaultSource\"/> is null.</exception>\n        public static IObservable<TResult> Case<TValue, TResult>(Func<TValue> selector, IDictionary<TValue, IObservable<TResult>> sources, IObservable<TResult> defaultSource)\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 (defaultSource == null)\n            {\n                throw new ArgumentNullException(nameof(defaultSource));\n            }\n\n            return s_impl.Case(selector, sources, defaultSource);\n        }\n\n        /// <summary>\n        /// Uses <paramref name=\"selector\"/> to determine which source in <paramref name=\"sources\"/> to return, choosing an empty sequence on the specified scheduler if no match is found.\n        /// </summary>","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Imperative.cs#L117-L153","documentation":"The three-argument Case overload throws ArgumentNullException when the selector delegate is null. Case invokes selector per subscription to pick a branch from the sources dictionary, so a null selector cannot be honored and is rejected eagerly at Observable.Imperative.cs:135.","triggerScenarios":"Calling Observable.Case<TValue,TResult>(selector, sources, defaultSource) with a null Func<TValue>, e.g. when the selector was meant to be built from configuration or injected and was never initialized.","commonSituations":"Dependency injection wiring misses the selector; a local Func variable assigned only in some branches; factory methods that return null instead of a default delegate.","solutions":["Supply a valid Func<TValue> that returns a key present in the dictionary (or one that falls through to defaultSource).","If a default key is appropriate, pass e.g. () => defaultKey instead of null.","Check the injection/factory path that was supposed to produce the selector."],"exampleFix":"// before\nFunc<string> selector = config.Mode == \"custom\" ? BuildSelector() : null;\nObservable.Case(selector, sources, defaultSrc);\n// after\nFunc<string> selector = config.Mode == \"custom\" ? BuildSelector() : () => \"default\";\nObservable.Case(selector, sources, defaultSrc);","handlingStrategy":"validation","validationCode":"if (selector is null) throw new ArgumentNullException(nameof(selector));\nvar result = Observable.Case(selector, sources, defaultSource);","typeGuard":null,"tryCatchPattern":"try { var q = Observable.Case(selector, sources, defaultSource); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"selector\") { /* rebuild selector from config or use a default-key selector */ }","preventionTips":["Never store Func<TValue> selectors as uninitialized nullable fields; give them constant defaults.","Validate DI-provided delegates at composition root startup.","Prefer returning a default-key selector from factories instead of null."],"tags":["argumentnull","reactive-extensions","case-operator","null-check"],"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"}