dotnet/reactive · error · ArgumentNullException
source
Error message
source
What it means
ArgumentNullException guard in AsyncObservable.SubscribeOn: the source async observable to be subscribed on the given scheduler was null. Since there is no sequence to schedule subscription work for, the operator throws before touching the scheduler.
Solutions
- Ensure the observable you call SubscribeOn on is non-null; check the upstream factory/method return value.
- Guard with a fallback observable if the source may legitimately be missing.
- If the pipeline is optional, skip SubscribeOn entirely when source is null.
Example fix
// before var obs = factory.Create(); // may return null var scheduled = obs.SubscribeOn(scheduler); // after var obs = factory.Create() ?? AsyncObservable.Empty<int>(); var scheduled = obs.SubscribeOn(scheduler);
Defensive patterns
Strategy: validation
Validate before calling
if (source == null)
throw new InvalidOperationException("Source observable must be non-null before SubscribeOn"); Type guard
static bool IsObservable<T>(IAsyncObservable<T>? o) => o is not null;
Try / catch
try
{
var scheduled = source.SubscribeOn(scheduler);
}
catch (ArgumentNullException ex) when (ex.ParamName == "source")
{
logger.LogError(ex, "Null observable passed to SubscribeOn");
scheduled = AsyncObservable.Empty<TSource>();
} Prevention
- Ensure every observable-producing method throws instead of returning null on failure.
- Coalesce with AsyncObservable.Empty<T>() when a source may be absent.
- Enable nullable reference type annotations on pipeline variables.
When it happens
Trigger: Calling someObservable.SubscribeOn(scheduler) where the receiver observable is null (e.g. a chain built from a null-returning factory or variable), or calling it as a static-style call SubscribeOn(null, scheduler).
Common situations: An observable-producing method returns null on an error path; conditional pipeline construction leaves the source unset; querying an optional configuration for the source.
Related errors
- Value cannot be null. (Parameter 'source')
- Value cannot be null. (Parameter 'source')
- Value cannot be null. (Parameter 'disposable1')
- Value cannot be null. (Parameter 'disposable2')
- Value cannot be null. (Parameter 'onNextAsync')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/de78d0aea1ba4ec6.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/SubscribeOn.cs:15
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT License.
// See the LICENSE file in the project root for more information.
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
namespace System.Reactive.Linq
{
public partial class AsyncObservable
{
public static IAsyncObservable<TSource> SubscribeOn<TSource>(this IAsyncObservable<TSource> source, IAsyncScheduler scheduler)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (scheduler == null)
throw new ArgumentNullException(nameof(scheduler));
return SubscribeOn(source, scheduler, scheduler);
}
public static IAsyncObservable<TSource> SubscribeOn<TSource>(this IAsyncObservable<TSource> source, IAsyncScheduler subscribeScheduler, IAsyncScheduler disposeScheduler)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (subscribeScheduler == null)
throw new ArgumentNullException(nameof(subscribeScheduler));
if (disposeScheduler == null)
throw new ArgumentNullException(nameof(disposeScheduler));
return CreateAsyncObservable<TSource>.From(
source,
(subscribeScheduler, disposeScheduler),View on GitHub (pinned to 94b5d5ab91)