{"record":{"id":"07dd6f34bb8ced5a","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-selector-case","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'selector')","messagePattern":"Value cannot be null\\. \\(Parameter 'selector'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/Case.cs","lineNumber":22,"sourceCode":"\nusing System.Collections.Generic;\n\nnamespace System.Linq\n{\n    public static partial class EnumerableEx\n    {\n        /// <summary>\n        /// Returns a sequence from a dictionary based on the result of evaluating a selector function.\n        /// </summary>\n        /// <typeparam name=\"TValue\">Type of the selector value.</typeparam>\n        /// <typeparam name=\"TResult\">Result sequence element type.</typeparam>\n        /// <param name=\"selector\">Selector function used to pick a sequence from the given sources.</param>\n        /// <param name=\"sources\">Dictionary mapping selector values onto resulting sequences.</param>\n        /// <returns>The source sequence corresponding with the evaluated selector value; otherwise, an empty sequence.</returns>\n        public static IEnumerable<TResult> Case<TValue, TResult>(Func<TValue> selector, IDictionary<TValue, IEnumerable<TResult>> sources)\n        {\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n            if (sources == null)\n                throw new ArgumentNullException(nameof(sources));\n\n            return Case(selector, sources, []);\n        }\n\n        /// <summary>\n        /// Returns a sequence from a dictionary based on the result of evaluating a selector function, also specifying a\n        /// default sequence.\n        /// </summary>\n        /// <typeparam name=\"TValue\">Type of the selector value.</typeparam>\n        /// <typeparam name=\"TResult\">Result sequence element type.</typeparam>\n        /// <param name=\"selector\">Selector function used to pick a sequence from the given sources.</param>\n        /// <param name=\"sources\">Dictionary mapping selector values onto resulting sequences.</param>\n        /// <param name=\"defaultSource\">\n        /// Default sequence to return in case there's no corresponding source for the computed\n        /// selector value.\n        /// </param>","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Case.cs#L4-L40","documentation":"The Case operator picks an IEnumerable<TResult> from a dictionary by invoking the supplied selector function. It eagerly validates arguments and throws ArgumentNullException with parameter name 'selector' when the selector delegate is null, failing fast before any enumeration occurs.","triggerScenarios":"Calling Case<TValue,TResult>(null, sources) with a null selector delegate; also indirectly via the overload with defaultSource and via a null factory in related overloads.","commonSituations":"Selector supplied from a config-resolved delegate or DI construction that returned null; refactoring left the lambda uninitialized.","solutions":["Pass a non-null Func<TValue> selector to Case","Check the value-producing code path (config/DI) that yielded a null delegate","Guard with null check before calling Case"],"exampleFix":"// before\nFunc<int> selector = config?.GetSelector(); // may be null\nvar seq = Case(selector, sources);\n// after\nvar sel = config?.GetSelector() ?? throw new InvalidOperationException(\"selector not configured\");\nvar seq = Case(sel, sources);","handlingStrategy":"validation","validationCode":"if (selector == null) throw new ArgumentException(\"selector must not be null\", nameof(selector));","typeGuard":"bool IsValidCaseCall<TValue>(Func<TValue> selector) => selector != null;","tryCatchPattern":"try { seq = Case(selector, sources); } catch (ArgumentNullException ex) when (ex.ParamName == \"selector\") { seq = Enumerable.Empty<TResult>(); }","preventionTips":["Null-check delegates before passing to eager-validating operators","Never source delegates from code paths that can return null without checking","Prefer throwing at the configuration site with a clearer message"],"tags":["ix","null-argument","linq","argument-validation"],"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"}