dotnet/reactive · error · ArgumentNullException

progress (Parameter 'progress')

Error message

progress (Parameter 'progress')

What it means

ToObservable(this IAsyncActionWithProgress<TProgress>, IProgress<TProgress>) throws ArgumentNullException when the progress parameter is null. The extension requires an IProgress<TProgress> receiver to forward WinRT progress reports into the observable pipeline before delegating to the internal ToObservable_ helper. Passing null means there is no destination for progress notifications, so the call is rejected immediately.

Solutions

  1. Pass a non-null IProgress<TProgress> implementation (e.g. new Progress<TProgress>(p => ...) or an observer's ToProgress()).
  2. If you don't need progress reports, call the single-argument overload source.ToObservable() (IAsyncActionWithProgress without progress) or ToObservableProgress() instead.
  3. Guard the value before calling: if (progress == null) progress = new Progress<TProgress>(_ => { }); or throw a more descriptive error at your own boundary.

Example fix

// before
var sub = actionWithProgress.ToObservable(null).Subscribe(onNext);
// after
var progress = new Progress<double>(p => Console.WriteLine($"{p:P}"));
var sub = actionWithProgress.ToObservable(progress).Subscribe(onNext);
Defensive patterns

Strategy: validation

Validate before calling

if (progress is null) throw new ArgumentNullException(nameof(progress));
var sub = actionWithProgress.ToObservable(progress);

Type guard

bool HasProgress<TProgress>(IProgress<TProgress>? p) => p is not null;

Try / catch

try { var sub = action.ToObservable(progress); }
catch (ArgumentNullException ex) when (ex.ParamName == "progress") { /* supply default progress or surface error */ }

Prevention

When it happens

Trigger: Calling source.ToObservable(progress) on an IAsyncActionWithProgress<TProgress> with progress == null, e.g. from a variable that was never initialized or a method parameter forwarded straight through.

Common situations: Forwarding an optional IProgress<TProgress> that the caller left null; calling from generated WinRT interop code where the progress argument was defaulted to null; refactoring from the progress-less ToObservable() overload but keeping a null second argument.

Related errors


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

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Foundation/AsyncInfoExtensions.cs:79

        /// <summary>
        /// Converts a Windows Runtime asynchronous action to an observable sequence, reporting its progress through the supplied progress object.
        /// Each observer subscribed to the resulting observable sequence will be notified about the action's successful or exceptional completion.
        /// </summary>
        /// <typeparam name="TProgress">The type of the reported progress objects.</typeparam>
        /// <param name="source">Asynchronous action to convert.</param>
        /// <param name="progress">Progress object to receive progress notifications on.</param>
        /// <returns>An observable sequence that produces a unit value when the asynchronous action completes, or propagates the exception produced by the asynchronous action.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="progress"/> is null.</exception>
        public static IObservable<Unit> ToObservable<TProgress>(this IAsyncActionWithProgress<TProgress> source, IProgress<TProgress> progress)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

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

            return source.ToObservable_(progress);
        }

        /// <summary>
        /// Converts a Windows Runtime asynchronous action to an observable sequence reporting its progress.
        /// Each observer subscribed to the resulting observable sequence will be notified about the action's successful or exceptional completion.
        /// </summary>
        /// <typeparam name="TProgress">The type of the reported progress objects.</typeparam>
        /// <param name="source">Asynchronous action to convert.</param>
        /// <returns>An observable sequence that produces progress values from the asynchronous action and notifies observers about the action's completion.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
        public static IObservable<TProgress> ToObservableProgress<TProgress>(this IAsyncActionWithProgress<TProgress> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));

View on GitHub (pinned to 94b5d5ab91)