dotnet/reactive · error · ArgumentNullException
scheduler
Error message
scheduler
What it means
StartAsync<TSource>(Func<ValueTask<TSource>>, IAsyncScheduler) throws ArgumentNullException when the scheduler parameter is null. The scheduler governs where the async work runs; the library requires an explicit instance rather than treating null as 'immediate'.
Solutions
- Supply a real scheduler, e.g. ImmediateAsyncScheduler.Instance
- Use the single-argument overload StartAsync(functionAsync) which defaults to ImmediateAsyncScheduler.Instance
- Repair the configuration that yielded a null scheduler
Example fix
// before StartAsync(fetch, null); // after StartAsync(fetch, ImmediateAsyncScheduler.Instance);
Defensive patterns
Strategy: validation
Validate before calling
if (scheduler == null) scheduler = ImmediateAsyncScheduler.Instance; // or choose the 1-arg overload
Type guard
static bool IsValidScheduler(IAsyncScheduler s) => s is not null;
Prevention
- Default to ImmediateAsyncScheduler.Instance when no scheduler is configured
- Centralize scheduler resolution in one non-null-returning provider
When it happens
Trigger: Calling StartAsync(functionAsync, null) with a valid function but a null IAsyncScheduler.
Common situations: Unconfigured scheduler dependency, tests passing null, copy-paste from code that used the overload without a scheduler.
Related errors
- null (Parameter 'scheduler')
- Value cannot be null. (Parameter 'observer')
- Value cannot be null. (Parameter 'values')
- scheduler (Value cannot be null)
- null (Parameter 'values')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/3ec42fc82e903d0e.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/StartAsync.cs:21
// See the LICENSE file in the project root for more information.
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
namespace System.Reactive.Linq
{
public partial class AsyncObservable
{
public static IAsyncObservable<TSource> StartAsync<TSource>(Func<ValueTask<TSource>> functionAsync) => StartAsync(functionAsync, ImmediateAsyncScheduler.Instance);
public static IAsyncObservable<TSource> StartAsync<TSource>(Func<ValueTask<TSource>> functionAsync, IAsyncScheduler scheduler)
{
if (functionAsync == null)
throw new ArgumentNullException(nameof(functionAsync));
if (scheduler == null)
throw new ArgumentNullException(nameof(scheduler));
Task<TSource> task;
try
{
task = functionAsync().AsTask();
}
catch (Exception ex)
{
return Throw<TSource>(ex);
}
return task.ToAsyncObservable(scheduler);
}
public static IAsyncObservable<TSource> StartAsync<TSource>(Func<CancellationToken, ValueTask<TSource>> functionAsync) => StartAsync(functionAsync, ImmediateAsyncScheduler.Instance);
public static IAsyncObservable<TSource> StartAsync<TSource>(Func<CancellationToken, ValueTask<TSource>> functionAsync, IAsyncScheduler scheduler)View on GitHub (pinned to 94b5d5ab91)