{"record":{"id":"8c5cfaa8deb13d74","repo":"dotnet/reactive","slug":"selector-windowsobservable-standardsequenceoperators","errorCode":null,"errorMessage":"selector","messagePattern":"selector","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/WindowsObservable.StandardSequenceOperators.cs","lineNumber":32,"sourceCode":"        /// Projects each element of an observable sequence to a Windows Runtime asynchronous operation and merges all of the asynchronous operation results into one observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the result produced by the projected asynchronous operations and the elements in the merged result sequence.</typeparam>\n        /// <param name=\"source\">An observable sequence of elements to project.</param>\n        /// <param name=\"selector\">A transform function to apply to each element.</param>\n        /// <returns>An observable sequence whose elements are the result of the asynchronous operations executed for each element of the input sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"selector\"/> is null.</exception>\n        /// <remarks>This overload supports composition of observable sequences and Windows Runtime asynchronous operations, without requiring manual conversion of the asynchronous operations to observable sequences using <see cref=\"AsyncInfoObservableExtensions.ToObservable{TResult}(IAsyncOperation{TResult})\"/>.</remarks>\n        public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, IAsyncOperation<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 source.SelectMany(x => selector(x).ToObservable());\n        }\n\n        /// <summary>\n        /// Projects each element of an observable sequence to a Windows Runtime asynchronous operation and merges all of the asynchronous operation results into one observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the result produced by the projected asynchronous operations and the elements in the merged result sequence.</typeparam>\n        /// <typeparam name=\"TProgress\">The type of the reported progress objects, which get ignored by this query operator.</typeparam>\n        /// <param name=\"source\">An observable sequence of elements to project.</param>\n        /// <param name=\"selector\">A transform function to apply to each element.</param>\n        /// <returns>An observable sequence whose elements are the result of the asynchronous operations executed for each element of the input sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"selector\"/> is null.</exception>\n        /// <remarks>This overload supports composition of observable sequences and Windows Runtime asynchronous operations, without requiring manual conversion of the asynchronous operations to observable sequences using <see cref=\"AsyncInfoObservableExtensions.ToObservable{TResult}(IAsyncOperation{TResult})\"/>.</remarks>\n        public static IObservable<TResult> SelectMany<TSource, TResult, TProgress>(this IObservable<TSource> source, Func<TSource, IAsyncOperationWithProgress<TResult, TProgress>> selector)\n        {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/WindowsObservable.StandardSequenceOperators.cs#L14-L50","documentation":"The SelectMany overload that maps each element to an IAsyncOperation (WinRT) throws ArgumentNullException when the selector delegate is null. Rx validates arguments eagerly at subscription composition time so failures surface at the call site rather than inside the pipeline. A null selector means the library has no way to produce a per-element asynchronous operation.","triggerScenarios":"Calling source.SelectMany(x => someAsyncOp) where the lambda variable or a captured delegate field holding the selector is null, e.g. selector passed in as a parameter and forwarded without a null check.","commonSituations":"Conditional composition where a selector is only assigned on one code path; DI-injected converter delegates that failed to register; refactoring that left a null default for an optional selector parameter.","solutions":["Ensure a non-null selector delegate is passed to SelectMany before calling it.","If the selector is optional, guard with `if (selector != null) source.SelectMany(selector)` or use a default selector.","Check DI configuration / factory registration so the delegate actually resolves to an instance."],"exampleFix":"// before\nsource.SelectMany(_selector.ToObservable()); // _selector is null\n// after\nif (_selector == null) throw new InvalidOperationException(\"selector not configured\");\nsource.SelectMany(x => _selector(x).ToObservable());","handlingStrategy":"validation","validationCode":"if (source == null) throw new ArgumentNullException(nameof(source));\nif (selector == null) throw new ArgumentNullException(nameof(selector));","typeGuard":"bool IsValidSelector<TSource, TResult>(Func<TSource, IAsyncOperation<TResult>> s) => s != null;","tryCatchPattern":"try { return source.SelectMany(x => selector(x).ToObservable()); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"selector\") { /* substitute default selector or rethrow with context */ throw; }","preventionTips":["Never pass nullable Func parameters straight into Rx operators","Use method groups instead of nullable delegate fields where possible","Assert delegate arguments in wrapper/helper APIs"],"tags":["argument-null","rx","linq","winrt"],"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"}