dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'source')

Error message

Value cannot be null. (Parameter 'source')

What it means

The parameterless ToObservable extension for IAsyncAction (WindowsRuntime) throws ArgumentNullException when the WinRT IAsyncAction source is null. The bridge object it constructs hooks the action's Completed event, which requires a live async action instance.

Solutions

  1. Check the IAsyncAction for null before calling ToObservable and handle the null case explicitly.
  2. Fix or guard the WinRT API call so it returns a valid action.
  3. Wrap the conversion so a null source yields an error observable instead of throwing at setup.

Example fix

// before
operation.ToObservable().Subscribe(...); // operation is null
// after
if (operation != null) { operation.ToObservable().Subscribe(...); }
else { HandleMissingOperation(); }
Defensive patterns

Strategy: validation

Validate before calling

if (source is null) { HandleMissingOperation(); return; }
source.ToObservable();

Type guard

bool HasAction(Windows.Foundation.IAsyncAction a) => a is not null;

Try / catch

try { source.ToObservable().Subscribe(obs); } catch (ArgumentNullException ex) when (ex.ParamName == "source") { Log("IAsyncAction was null"); }

Prevention

When it happens

Trigger: Calling ((IAsyncAction)null).ToObservable(), typically when an async WinRT API returned null instead of an action (some APIs return null on fast-fail or when unsupported).

Common situations: UWP/WinRT interop where a projected async operation came back null from a platform call or a mock; calling on platforms where the WinRT type projection is unavailable.

Related errors


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

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive.WindowsRuntime/AsyncInfoObservableExtensions.cs:35

    /// Provides conversions from Windows Runtime asynchronous actions and operations to observable sequences.
    /// </summary>
    [CLSCompliant(false)]
    public static class AsyncInfoObservableExtensions
    {
        #region IAsyncAction and IAsyncActionWithProgress

        /// <summary>
        /// Converts a Windows Runtime asynchronous action to an observable sequence.
        /// Each observer subscribed to the resulting observable sequence will be notified about the action's successful or exceptional completion.
        /// </summary>
        /// <param name="source">Asynchronous action to convert.</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"/> is null.</exception>
        public static IObservable<Unit> ToObservable(this IAsyncAction source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return new AsyncInfoToObservableBridge<Unit, Unit>(
                source,
                static (iai, a) => ((IAsyncAction)iai).Completed += new AsyncActionCompletedHandler((iaa, status) => a(iaa, status)),
                iai => Unit.Default,
                onProgress: null,
                progress: null,
                multiValue: false
            );
        }

        /// <summary>
        /// Converts a Windows Runtime asynchronous action to an observable sequence, ignoring its progress notifications.
        /// 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, which get ignored by this conversion.</typeparam>
        /// <param name="source">Asynchronous action to convert.</param>

View on GitHub (pinned to 94b5d5ab91)