dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'source')
Error message
Value cannot be null. (Parameter 'source')
What it means
The UWP ObserveOn extension requires a non-null source observable; passing null throws ArgumentNullException('source'). Rx guards argument nulls eagerly at the operator call site so the failure happens immediately rather than inside the subscription pipeline.
Solutions
- Check why the source observable is null before calling ObserveOn; initialize or assign it (e.g. Observable.Empty<TSource>() as a safe default).
- Add a null/has-value check on the variable producing the source sequence.
- If the source comes from an event or property, ensure the publisher actually assigned the observable before the UI subscription runs.
Example fix
// before IObservable<int> source = GetSource(); // may return null var obs = source.ObserveOn(myControl); // after var src = GetSource() ?? Observable.Empty<int>(); var obs = src.ObserveOn(myControl);
Defensive patterns
Strategy: validation
Validate before calling
if (source == null) source = Observable.Empty<TSource>(); var obs = source.ObserveOn(dependencyObject);
Type guard
static IObservable<T> NotNull<T>(IObservable<T> s) => s ?? Observable.Empty<T>();
Try / catch
try
{
var obs = source.ObserveOn(dependencyObject);
}
catch (ArgumentNullException ex) when (ex.ParamName == "source")
{
// fall back to empty/default sequence
} Prevention
- Never let factory methods return null observables; return Observable.Empty<T>() or Observable.Never<T>().
- Initialize observable fields at declaration or in the constructor.
- Enable nullable reference types (C# 8+) so null sources are caught at compile time.
When it happens
Trigger: Calling source.ObserveOn(dependencyObject) (System.Reactive.Uwp DependencyObjectObservable, line 34) where the IObservable<TSource> argument is null.
Common situations: A factory method or property returning null observable, a nullable field not yet initialized, or a method chain where an earlier operator returned null instead of an empty sequence.
Related errors
- Value cannot be null. (Parameter 'subscribe')
- Value cannot be null. (Parameter 'fourteenth')
- throw new ArgumentNullException(nameof(source));
- Value cannot be null. (Parameter 'dependencyObject')
- Value cannot be null. (Parameter 'observer')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/5f450aa04138e446.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive.Uwp/System.Reactive.Linq/DependencyObjectObservable.cs:34
/// <summary>
/// Rx extension methods for UWP's (Windows.UI.Xaml) <see cref="DependencyObject"/>.
/// </summary>
[CLSCompliant(false)]
public static class DependencyObjectObservable
{
/// <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>View on GitHub (pinned to 94b5d5ab91)