{"record":{"id":"3687c2f909baada9","repo":"dotnet/reactive","slug":"sources","errorCode":null,"errorMessage":"sources","messagePattern":"sources","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Imperative.cs","lineNumber":140,"sourceCode":"        /// </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>\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=\"scheduler\">Scheduler to generate an empty sequence on in case no matching source in <paramref name=\"sources\"/> is found.</param>","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Imperative.cs#L122-L158","documentation":"The Case(selector, sources, defaultSource) overload throws ArgumentNullException when the sources dictionary is null. The dictionary defines the branch mapping from selector values to observables, so a null map is invalid and rejected at Observable.Imperative.cs:140 before delegation.","triggerScenarios":"Calling Observable.Case with null in the second parameter (IDictionary<TValue, IObservable<TResult>>), e.g. a dictionary built lazily or loaded from config that was never populated/created.","commonSituations":"Conditional initialization where the branch table is only built in one environment; a lookup helper returning null on miss; deserialization of route tables that produced null.","solutions":["Construct and pass a populated IDictionary<TValue, IObservable<TResult>> (it may be empty if you always want defaultSource).","Guard the producing method so it returns an empty dictionary rather than null.","Initialize the dictionary before wiring the Case operator."],"exampleFix":"// before\nIDictionary<string, IObservable<int>> routes = LoadRoutes(); // may be null\nObservable.Case(GetKey, routes, fallback);\n// after\nIDictionary<string, IObservable<int>> routes = LoadRoutes() ?? new Dictionary<string, IObservable<int>>();\nObservable.Case(GetKey, routes, fallback);","handlingStrategy":"validation","validationCode":"if (sources is null) throw new ArgumentNullException(nameof(sources));\nvar result = Observable.Case(selector, sources, defaultSource);","typeGuard":null,"tryCatchPattern":"try { var q = Observable.Case(selector, sources, defaultSource); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"sources\") { /* fall back to a defaultSource-only observable */ }","preventionTips":["Use non-nullable dictionary fields with initializers so they are always constructed.","Make loader methods return empty dictionaries rather than null.","Validate branch-table construction at startup, not at operator call time."],"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"}