{"record":{"id":"34c353f1934b6974","repo":"dotnet/reactive","slug":"resultselector-parameter-resultselector","errorCode":null,"errorMessage":"resultSelector (Parameter 'resultSelector')","messagePattern":"resultSelector \\(Parameter 'resultSelector'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/AsyncInfoObservable.cs","lineNumber":170,"sourceCode":"        /// Creates a Windows Runtime asynchronous operation that returns the last element of the result sequence, reporting incremental progress for each element produced by the source sequence.\n        /// Upon cancellation of the asynchronous operation, the subscription to the source sequence will be disposed.\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.</typeparam>\n        /// <param name=\"source\">Source sequence to compute a result sequence that gets exposed as an asynchronous operation.</param>\n        /// <param name=\"resultSelector\">Selector function to map the source sequence on a result sequence.</param>\n        /// <returns>Windows Runtime asynchronous operation object that returns the last element of the result sequence, reporting incremental progress for each source sequence element.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"resultSelector\"/> is null.</exception>\n        public static IAsyncOperationWithProgress<TResult, int> ToAsyncOperationWithProgress<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> resultSelector)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (resultSelector == null)\n            {\n                throw new ArgumentNullException(nameof(resultSelector));\n            }\n\n            return AsyncInfo.Run<TResult, int>((ct, progress) =>\n            {\n                var i = 0;\n                return resultSelector(source.Do(_ => progress.Report(i++))).ToTask(ct);\n            });\n        }\n\n        /// <summary>\n        /// Creates a Windows Runtime asynchronous operation that returns the last element of the result sequence, using a selector function to map the source sequence on a progress reporting sequence.\n        /// Upon cancellation of the asynchronous operation, the subscription to the source sequence will be disposed.\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.</typeparam>\n        /// <typeparam name=\"TProgress\">The type of the elements in the progress sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to compute a result sequence that gets exposed as an asynchronous operation and a progress sequence that gets reported through the asynchronous operation.</param>\n        /// <param name=\"resultSelector\">Selector function to map the source sequence on a result sequence.</param>","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/AsyncInfoObservable.cs#L152-L188","documentation":"This ToAsyncOperationWithProgress overload throws ArgumentNullException named 'resultSelector' when the provided resultSelector function is null. The selector maps the source observable (with progress reporting) to the observable producing the operation result.","triggerScenarios":"Calling source.ToAsyncOperationWithProgress<TSource, TResult>(null) or passing an uninitialized Func variable.","commonSituations":"Selectors built dynamically (reflection, config, DI) that resolve to null; optional parameters forwarded without defaults.","solutions":["Supply a valid resultSelector function","Apply a default selector with null-coalescing if the parameter is optional","Fix the code path that produces a null Func"],"exampleFix":"// before\nsource.ToAsyncOperationWithProgress<TSource, TResult>(resultSelector); // null\n// after\nsource.ToAsyncOperationWithProgress<TSource, TResult>(resultSelector ?? (o => o.TakeLast(1).Select(x => Project(x))));","handlingStrategy":"validation","validationCode":"if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));","typeGuard":"static bool IsValidSelector<TSource,TResult>(Func<IObservable<TSource>, IObservable<TResult>>? selector) => selector is not null;","tryCatchPattern":"try { op = source.ToAsyncOperationWithProgress(selector); } catch (ArgumentNullException ex) when (ex.ParamName == \"resultSelector\") { /* supply default selector */ }","preventionTips":["Provide default result selectors for optional parameters","Null-check dynamically constructed delegates","Use nullable function type annotations to surface potential nulls"],"tags":["null-argument","argumentnull","winrt","async-operation"],"backgroundTag":"missing-required-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"}