{"record":{"id":"790d40e9c69450df","repo":"dotnet/reactive","slug":"resultselector-windowsobservable-standardsequenceoperators","errorCode":null,"errorMessage":"resultSelector","messagePattern":"resultSelector","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/WindowsObservable.StandardSequenceOperators.cs","lineNumber":90,"sourceCode":"        /// <param name=\"resultSelector\">A transform function to apply to each element of the intermediate sequence.</param>\n        /// <returns>An observable sequence whose elements are the result of obtaining an asynchronous operation for each element of the input sequence and then mapping the asynchronous operation's result and its corresponding source element to a result element.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"asyncOperationSelector\"/> or <paramref name=\"resultSelector\"/> is null.</exception>\n        /// <remarks>This overload supports using LINQ query comprehension syntax in C# and Visual Basic to compose 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, TAsyncOperationResult, TResult>(this IObservable<TSource> source, Func<TSource, IAsyncOperation<TAsyncOperationResult>> asyncOperationSelector, Func<TSource, TAsyncOperationResult, TResult> resultSelector)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (asyncOperationSelector == null)\n            {\n                throw new ArgumentNullException(nameof(asyncOperationSelector));\n            }\n\n            if (resultSelector == null)\n            {\n                throw new ArgumentNullException(nameof(resultSelector));\n            }\n\n            return source.SelectMany(x => asyncOperationSelector(x).ToObservable(), resultSelector);\n        }\n\n        /// <summary>\n        /// Projects each element of an observable sequence to a Windows Runtime asynchronous operation, invokes the result selector for the source element and the asynchronous operation result, and merges the results into one observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TAsyncOperationResult\">The type of the results produced by the projected asynchronous operations.</typeparam>\n        /// <typeparam name=\"TAsyncOperationProgress\">The type of the reported progress objects, which get ignored by this query operator.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate asynchronous operation results.</typeparam>\n        /// <param name=\"source\">An observable sequence of elements to project.</param>\n        /// <param name=\"asyncOperationSelector\">A transform function to apply to each element.</param>\n        /// <param name=\"resultSelector\">A transform function to apply to each element of the intermediate sequence.</param>\n        /// <returns>An observable sequence whose elements are the result of obtaining an asynchronous operation for each element of the input sequence and then mapping the asynchronous operation's result and its corresponding source element to a result element.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"asyncOperationSelector\"/> or <paramref name=\"resultSelector\"/> is null.</exception>\n        /// <remarks>This overload supports using LINQ query comprehension syntax in C# and Visual Basic to compose 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>","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/WindowsObservable.StandardSequenceOperators.cs#L72-L108","documentation":"The two-argument SelectMany overload throws ArgumentNullException when resultSelector, the Func<TSource, TAsyncOperationResult, TResult> combining element and async result, is null. The result selector defines the projection of the composed query, so null is rejected at composition time. This validation is eager, not deferred to subscription.","triggerScenarios":"source.SelectMany(opSelector, resultSelector) where the resultSelector argument is null, e.g. a nullable Func parameter, a query-comprehension lowering with a missing projection, or a captured field never assigned.","commonSituations":"Building queries dynamically where the projection is conditionally supplied; helper APIs with optional projector parameters; unit tests passing null placeholders.","solutions":["Pass a concrete result selector, e.g. (x, r) => new Result(x, r).","If projection is identity, supply (x, r) => r instead of null.","Null-check the projector before composing the query."],"exampleFix":"// before\nsrc.SelectMany(x => x.LoadAsync(), null); // projection missing\n// after\nsrc.SelectMany(x => x.LoadAsync(), (x, r) => r);","handlingStrategy":"validation","validationCode":"if (resultSelector == null) resultSelector = (x, r) => r; // identity fallback","typeGuard":"bool HasResultSelector<TSource, TRes, TResult>(Func<TSource, TRes, TResult> rs) => rs != null;","tryCatchPattern":"try { return source.SelectMany(opSelector, resultSelector); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"resultSelector\") { return source.SelectMany(opSelector, (x, r) => r); }","preventionTips":["Use (x, r) => r instead of null for pass-through projections","Make projector parameters non-optional in helper APIs","Never stub projections with null in tests"],"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"}