dotnet/reactive · error · ArgumentNullException

resultSelector (Parameter 'resultSelector')

Error message

resultSelector (Parameter 'resultSelector')

What it means

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.

Solutions

  1. Supply a valid resultSelector function
  2. Apply a default selector with null-coalescing if the parameter is optional
  3. Fix the code path that produces a null Func

Example fix

// before
source.ToAsyncOperationWithProgress<TSource, TResult>(resultSelector); // null
// after
source.ToAsyncOperationWithProgress<TSource, TResult>(resultSelector ?? (o => o.TakeLast(1).Select(x => Project(x))));
Defensive patterns

Strategy: validation

Validate before calling

if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector));

Type guard

static bool IsValidSelector<TSource,TResult>(Func<IObservable<TSource>, IObservable<TResult>>? selector) => selector is not null;

Try / catch

try { op = source.ToAsyncOperationWithProgress(selector); } catch (ArgumentNullException ex) when (ex.ParamName == "resultSelector") { /* supply default selector */ }

Prevention

When it happens

Trigger: Calling source.ToAsyncOperationWithProgress<TSource, TResult>(null) or passing an uninitialized Func variable.

Common situations: Selectors built dynamically (reflection, config, DI) that resolve to null; optional parameters forwarded without defaults.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15). Data as JSON: /api/errors/34c353f1934b6974. Report an issue: GitHub.

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Linq/AsyncInfoObservable.cs:170

        /// 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.
        /// Upon cancellation of the asynchronous operation, the subscription to the source sequence will be disposed.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
        /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
        /// <param name="source">Source sequence to compute a result sequence that gets exposed as an asynchronous operation.</param>
        /// <param name="resultSelector">Selector function to map the source sequence on a result sequence.</param>
        /// <returns>Windows Runtime asynchronous operation object that returns the last element of the result sequence, reporting incremental progress for each source sequence element.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="resultSelector"/> is null.</exception>
        public static IAsyncOperationWithProgress<TResult, int> ToAsyncOperationWithProgress<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> resultSelector)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (resultSelector == null)
            {
                throw new ArgumentNullException(nameof(resultSelector));
            }

            return AsyncInfo.Run<TResult, int>((ct, progress) =>
            {
                var i = 0;
                return resultSelector(source.Do(_ => progress.Report(i++))).ToTask(ct);
            });
        }

        /// <summary>
        /// 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.
        /// Upon cancellation of the asynchronous operation, the subscription to the source sequence will be disposed.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
        /// <typeparam name="TResult">The type of the elements in the result sequence.</typeparam>
        /// <typeparam name="TProgress">The type of the elements in the progress sequence.</typeparam>
        /// <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>
        /// <param name="resultSelector">Selector function to map the source sequence on a result sequence.</param>

View on GitHub (pinned to 94b5d5ab91)