dotnet/reactive · error · ArgumentNullException

Value cannot be null. (Parameter 'dependencyObject')

Error message

Value cannot be null. (Parameter 'dependencyObject')

What it means

The UWP ObserveOn extension requires a non-null DependencyObject; passing null throws ArgumentNullException('dependencyObject'). The dependencyObject supplies the CoreDispatcher that observations will be marshalled to, so a null target has no valid scheduling destination.

Solutions

  1. Pass a valid DependencyObject (the page, control, or window) and defer the ObserveOn call until the control exists (e.g. in OnNavigatedTo or Loaded event).
  2. Guard with a null check before subscribing and skip or log when no UI target is available.
  3. Verify bindings/FindName actually resolved the control instead of returning null.

Example fix

// before
source.ObserveOn((DependencyObject)null);
// after
if (myControl != null)
{
    source.ObserveOn(myControl);
}
Defensive patterns

Strategy: validation

Validate before calling

if (dependencyObject != null)
{
    var obs = source.ObserveOn(dependencyObject);
}

Type guard

static bool HasUiTarget(DependencyObject d) => d is not null;

Try / catch

try
{
    var obs = source.ObserveOn(dependencyObject);
}
catch (ArgumentNullException ex) when (ex.ParamName == "dependencyObject")
{
    // defer or skip UI-marshalled subscription
}

Prevention

When it happens

Trigger: Calling source.ObserveOn(null) (DependencyObjectObservable, line 39), e.g. a UI control or page reference that is null when the subscription is set up.

Common situations: Accessing a control before InitializeComponent / page Loaded, a DataContext-bound element not yet materialized, or code running before the XAML visual tree is built.

Related errors


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

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive.Uwp/System.Reactive.Linq/DependencyObjectObservable.cs:39

    {
        /// <summary>
        /// Wraps the source sequence in order to run its observer callbacks on the dispatcher associated with the specified object.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
        /// <param name="source">Source sequence.</param>
        /// <param name="dependencyObject">Object to get the dispatcher from.</param>
        /// <returns>The source sequence whose observations happen on the specified object's dispatcher.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="dependencyObject"/> is null.</exception>
        public static IObservable<TSource> ObserveOn<TSource>(this IObservable<TSource> source, DependencyObject dependencyObject)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

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

            return Synchronization.ObserveOn(source, new CoreDispatcherScheduler(dependencyObject.Dispatcher));
        }

        /// <summary>
        /// Wraps the source sequence in order to run its observer callbacks on the dispatcher associated with the specified object.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
        /// <param name="source">Source sequence.</param>
        /// <param name="dependencyObject">Object to get the dispatcher from.</param>
        /// <param name="priority">Priority to schedule work items at.</param>
        /// <returns>The source sequence whose observations happen on the specified object's dispatcher.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="dependencyObject"/> is null.</exception>
        public static IObservable<TSource> ObserveOn<TSource>(this IObservable<TSource> source, DependencyObject dependencyObject, CoreDispatcherPriority priority)
        {
            if (source == null)
            {

View on GitHub (pinned to 94b5d5ab91)