{"record":{"id":"93f85356fbd9b032","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-selector-queryablepattern","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'selector')","messagePattern":"Value cannot be null\\. \\(Parameter 'selector'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Joins/QueryablePattern.Generated.cs","lineNumber":65,"sourceCode":"                    Expression,\n                    m,\n                    Qbservable.GetSourceExpression(other)\n                )\n            );\n        }\n\n        /// <summary>\n        /// Matches when all observable sequences have an available element and projects the elements by invoking the selector function.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence, returned by the selector function.</typeparam>\n        /// <param name=\"selector\">Selector that will be invoked for elements in the source sequences.</param>\n        /// <returns>Plan that produces the projected results, to be fed (with other plans) to the When operator.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"selector\"/> is null.</exception>\n        public QueryablePlan<TResult> Then<TResult>(Expression<Func<TSource1, TSource2, TResult>> selector)\n        {\n            if (selector == null)\n            {\n                throw new ArgumentNullException(nameof(selector));\n            }\n\n            var t = typeof(QueryablePattern<TSource1, TSource2>);\n            var m = t.GetMethod(nameof(Then)).MakeGenericMethod(typeof(TResult));\n            return new QueryablePlan<TResult>(\n                Expression.Call(\n                    Expression,\n                    m,\n                    selector\n                )\n            );\n        }\n    }\n\n    /// <summary>\n    /// Represents a join pattern over three observable sequences.\n    /// </summary>\n    /// <typeparam name=\"TSource1\">The type of the elements in the first source sequence.</typeparam>","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Joins/QueryablePattern.Generated.cs#L47-L83","documentation":"This ArgumentNullException is thrown by QueryablePattern<TSource1,TSource2>.Then<TResult> when the selector expression is null. The Rx Queryable pattern builds an expression tree describing the join, so a non-null selector expression is mandatory; the guard at the top of the method fails fast instead of failing later inside Expression.Call.","triggerScenarios":"Calling Then<TSource1,TSource2,TResult>((Expression<Func<TSource1,TSource2,TResult>>)null) — e.g. passing a null result of a factory, a variable that was never assigned, or a conditional expression that evaluated to null.","commonSituations":"Building IQbservable join queries where the selector comes from configuration, reflection, or an optional delegate parameter; refactoring that removed a lambda but left the Then call; type mismatches forcing a cast of null.","solutions":["Pass a valid Expression<Func<TSource1,TSource2,TResult>> lambda to Then, e.g. (a, b) => new Result(a, b)","Check the variable holding the selector for null before calling Then and fix the assignment path","If the selector is optional, return early or use a default projection instead of passing null"],"exampleFix":"// before\nExpression<Func<int, string, Result>> sel = GetSelector(); // returns null\nvar plan = pattern.Then(sel);\n// after\nvar sel = GetSelector() ?? ((int a, string b) => new Result(a, b));\nvar plan = pattern.Then(sel);","handlingStrategy":"validation","validationCode":"if (selector is null) throw new ArgumentException(\"selector must be a non-null expression\", nameof(selector));","typeGuard":"static bool IsValidSelector<TSource1,TSource2,TResult>(Expression<Func<TSource1,TSource2,TResult>>? s) => s is not null;","tryCatchPattern":"try { var plan = pattern.Then(selector); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"selector\") { /* log and supply default projection */ }","preventionTips":["Always pass expression lambdas directly inline to Then rather than via nullable variables","Enable nullable reference types so null selector variables are flagged at compile time","Never cast or convert Func delegates to Expression dynamically without a null check"],"tags":["csharp","null-argument","reactive-extensions","expression-tree"],"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"}