{"record":{"id":"034af0dafabdb7ac","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-resultselector-034af0","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'resultSelector')","messagePattern":"Value cannot be null\\. \\(Parameter 'resultSelector'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive.WindowsRuntime/System.Reactive.Linq/WindowsObservable.StandardSequenceOperators.cs","lineNumber":93,"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":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive.WindowsRuntime/System.Reactive.Linq/WindowsObservable.StandardSequenceOperators.cs#L75-L111","documentation":"This SelectMany overload throws ArgumentNullException when the resultSelector delegate is null. The resultSelector combines each source element with its async operation result, and is required for the composition, so Rx validates it eagerly at call time. The runtime-rendered message is \"Value cannot be null. (Parameter 'resultSelector')\".","triggerScenarios":"Calling source.SelectMany<TSource, TAsyncOperationResult, TResult>(asyncOperationSelector, resultSelector) where resultSelector is null.","commonSituations":"A projection delegate from settings/DI not supplied; overloads confused so the final Func landed as null; code generation or reflection emitting a null delegate for the combiner.","solutions":["Provide a non-null resultSelector, e.g. (x, r) => new Result(x.Id, r.Value).","Verify the two delegates are in the correct order (asyncOperationSelector first, resultSelector second).","If no combination is needed, use the simpler SelectMany(source, x => selector(x).ToObservable()) overload instead."],"exampleFix":"// before\nvar q = source.SelectMany(x => x.GetOperationAsync(), null);\n// after\nvar q = source.SelectMany(\n    (Item x) => x.GetOperationAsync(),\n    (Item x, OpResult r) => new Result(x.Id, r.Value));","handlingStrategy":"validation","validationCode":"if (resultSelector is null) throw new InvalidOperationException(\"resultSelector must be provided to combine element and async result\");","typeGuard":"static bool HasResultSelector<T, A, R>(Func<T, A, R>? resultSel) => resultSel is not null;","tryCatchPattern":"try { var q = source.SelectMany(asyncOpSelector, resultSelector); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"resultSelector\") { /* supply a default projection */ }","preventionTips":["Write the resultSelector as an inline lambda so it can never be null.","Check delegate argument order when converting from query syntax to method syntax.","If no per-element projection is needed, use the simpler two-argument SelectMany overload."],"tags":["argument-null","reactive-extensions","uwp","linq"],"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"}