{"record":{"id":"9835a24db91ea93f","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-selector-qbservableex","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(selector))","messagePattern":"throw new ArgumentNullException\\(nameof\\(selector\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs","lineNumber":1025,"sourceCode":"#endif\n\n#if !STABLE\n        /// <summary>\n        /// Expands an observable sequence by recursively invoking selector.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence and each of the recursively expanded sources obtained by running the selector function.</typeparam>\n        /// <param name=\"source\">Source sequence with the initial elements.</param>\n        /// <param name=\"selector\">Selector function to invoke for each produced element, resulting in another sequence to which the selector will be invoked recursively again.</param>\n        /// <returns>An observable sequence containing all the elements produced by the recursive expansion.</returns>\n        /// <exception cref=\"ArgumentNullException\">\n        /// <paramref name=\"source\" /> or <paramref name=\"selector\" /> is null.</exception>\n        [Experimental]\n        public static IQbservable<TSource> Expand<TSource>(this IQbservable<TSource> source, Expression<Func<TSource, IObservable<TSource>>> selector)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n\n            return source.Provider.CreateQuery<TSource>(\n                Expression.Call(\n                    null,\n                    new Func<IQbservable<TSource>, Expression<Func<TSource, IObservable<TSource>>>, IQbservable<TSource>>(Expand<TSource>).Method,\n                    source.Expression,\n                    selector\n                )\n            );\n        }\n#endif\n\n#if !STABLE\n        /// <summary>\n        /// Expands an observable sequence by recursively invoking selector, using the specified scheduler to enumerate the queue of obtained sequences.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence and each of the recursively expanded sources obtained by running the selector function.</typeparam>\n        /// <param name=\"source\">Source sequence with the initial elements.</param>","sourceCodeStart":1007,"sourceCodeEnd":1043,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs#L1007-L1043","documentation":"QbservableEx.Expand(source, selector) requires the expansion function as an Expression<Func<TSource, IObservable<TSource>>> so it can be embedded in the queryable expression tree. A null selector throws ArgumentNullException named 'selector'. Delegates are not acceptable here because remote query providers must inspect the expression.","triggerScenarios":"Calling source.Expand(null) — selector held in a nullable variable, conditionally assigned lambda, or produced by a builder that returned null.","commonSituations":"Config-driven operators where the expansion rule was not configured; refactoring that removed the lambda but kept the call; passing a Func where an Expression was expected and a failed conversion yielded null.","solutions":["Supply an expression lambda, e.g. x => Observable.Return(x), typed as Expression<Func<TSource, IObservable<TSource>>>","Skip Expand when no expansion rule exists instead of passing null","Fix the expression factory that returned null"],"exampleFix":"// before\nsource.Expand(selector); // selector is null\n// after\nExpression<Func<TSource, IObservable<TSource>>> selector = x => Observable.Return(x);\nsource.Expand(selector);","handlingStrategy":"validation","validationCode":"if (selector == null)\n    throw new InvalidOperationException(\"Expand selector expression is required\");","typeGuard":"bool HasSelector<T>(Expression<Func<T, IObservable<T>>> s) => s is not null;","tryCatchPattern":"try\n{\n    var query = source.Expand(selector);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"selector\")\n{\n    logger.LogError(ex, \"Expand selector was null\");\n}","preventionTips":["Pass expression lambdas directly to Expand instead of stored nullable lambdas","Treat a missing expansion rule as a skip-the-operator condition, not null","Verify Func vs Expression types when refactoring operator signatures"],"tags":["argumentnull","rx","expand","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-23T08:17:48.524Z"}