{"record":{"id":"ec8500949a0adbae","repo":"dotnet/reactive","slug":"defaultsource","errorCode":null,"errorMessage":"defaultSource","messagePattern":"defaultSource","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Imperative.cs","lineNumber":145,"sourceCode":"        /// <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>\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        {","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Imperative.cs#L127-L163","documentation":"The Case(selector, sources, defaultSource) overload throws ArgumentNullException when defaultSource is null. This overload uses the default observable when the selector's value is absent from the dictionary, so a null default defeats the operator's contract and is rejected at Observable.Imperative.cs:145.","triggerScenarios":"Calling Observable.Case(selector, sources, null) — commonly when a fallback observable expression evaluates to null or the developer assumed defaultSource was optional.","commonSituations":"Building the fallback via a factory that returns null; omission of the fallback during a refactor from the two-argument Case overload; config-driven fallback creation failing silently.","solutions":["Pass a real fallback observable, e.g. Observable.Empty<TResult>() if doing nothing is the desired default.","Use Observable.Throw<TResult>(...) to make the missing branch an explicit error instead of null.","If no fallback is needed, use the two-argument Case(selector, sources) overload."],"exampleFix":"// before\nObservable.Case(selector, sources, GetFallback()); // GetFallback() returns null when unset\n// after\nObservable.Case(selector, sources, GetFallback() ?? Observable.Empty<int>());","handlingStrategy":"validation","validationCode":"if (defaultSource is null) throw new ArgumentNullException(nameof(defaultSource));\nvar result = Observable.Case(selector, sources, defaultSource);","typeGuard":null,"tryCatchPattern":"try { var q = Observable.Case(selector, sources, defaultSource); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"defaultSource\") { /* use Observable.Empty<TResult>() as fallback */ }","preventionTips":["Always define an explicit fallback observable (Empty or Throw) in configuration.","If no fallback is meaningful, use the two-argument Case overload instead.","Coalesce null fallbacks at the call site: GetFallback() ?? Observable.Empty<T>()."],"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"}