{"record":{"id":"285b689d6fe109d9","repo":"dotnet/reactive","slug":"selector-qbservable-joins","errorCode":null,"errorMessage":"selector","messagePattern":"selector","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Qbservable.Joins.cs","lineNumber":65,"sourceCode":"        /// <summary>\n        /// Matches when the observable sequence has an available element and projects the element by invoking the selector function.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence, returned by the selector function.</typeparam>\n        /// <param name=\"source\">Observable sequence to apply the selector on.</param>\n        /// <param name=\"selector\">Selector that will be invoked for elements in the source sequence.</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=\"source\"/> or <paramref name=\"selector\"/> is null.</exception>\n        public static QueryablePlan<TResult> Then<TSource, TResult>(this IQbservable<TSource> source, Expression<Func<TSource, TResult>> selector)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (selector == null)\n            {\n                throw new ArgumentNullException(nameof(selector));\n            }\n\n            return new QueryablePlan<TResult>(\n                Expression.Call(\n                    null,\n                    new Func<IQbservable<TSource>, Expression<Func<TSource, TResult>>, QueryablePlan<TResult>>(Then).Method,\n                    source.Expression,\n                    selector\n                )\n            );\n        }\n\n        /// <summary>\n        /// Joins together the results from several patterns.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence, obtained from the specified patterns.</typeparam>\n        /// <param name=\"provider\">Query provider used to construct the <see cref=\"IQbservable{T}\"/> data source.</param>\n        /// <param name=\"plans\">A series of plans created by use of the Then operator on patterns.</param>","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Qbservable.Joins.cs#L47-L83","documentation":"Then's selector must be a non-null Expression<Func<TSource, TResult>> — unlike the observable variant, this must be an expression tree so it can be embedded in the queryable expression. Passing null (or an ordinary delegate where an expression is required) triggers ArgumentNullException(\"selector\") before the QueryablePlan is constructed.","triggerScenarios":"Calling source.Then(null) or passing a lambda variable typed as Expression<Func<TSource, TResult>> that is null; also passing a non-expression Func where the compiler would force conversion that fails at runtime with a null expression instance.","commonSituations":"Dynamic query construction where the projection expression is conditionally built and ends up null, or reflection-based composition that fails to compile the expression.","solutions":["Pass a concrete expression lambda, e.g. x => x.ToString().","Provide a default projection expression when the configured one is null.","Fix the expression-building code so it always compiles and assigns the selector."],"exampleFix":"// before\nExpression<Func<int, string>> proj = null;\nvar plan = source.Then(proj);\n// after\nExpression<Func<int, string>> proj = x => x.ToString();\nvar plan = source.Then(proj);","handlingStrategy":"validation","validationCode":"if (selector is null) selector = x => default!; // or fail fast\nvar plan = source.Then(selector);","typeGuard":"bool HasProjection<TIn, TOut>(Expression<Func<TIn, TOut>>? e) => e is not null;","tryCatchPattern":"try { var plan = source.Then(proj); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"selector\") { var plan = source.Then(x => default(TResult)!); }","preventionTips":["Pass expression lambdas directly at the call site","When building expressions dynamically, assert the compiled result is non-null","Remember the qbservable overload needs Expression<>, not a plain Func"],"tags":["argument-null","expression-tree","qbservable","rx","dotnet"],"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"}