dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'actionAsync')
Error message
Value cannot be null. (Parameter 'actionAsync')
What it means
Observable.StartAsync(Func<Task>) schedules the provided async function on the default concurrency scheduler and converts it into IObservable<Unit>. A null 'actionAsync' delegate throws ArgumentNullException at call time. The check happens eagerly so the failure is attributed to the caller, not to a later subscription.
Solutions
- Pass a non-null async lambda or method group to StartAsync.
- Guard the nullable delegate source with an explicit throw or fallback before the call.
- Register the Func<Task> in DI/config if that is where it comes from.
Example fix
// before
Func<Task> work = _workField; // may be null
var xs = Observable.StartAsync(work);
// after
var work = _workField ?? throw new InvalidOperationException("work not set");
var xs = Observable.StartAsync(work); Defensive patterns
Strategy: validation
Validate before calling
if (actionAsync is null)
throw new ArgumentNullException(nameof(actionAsync));
Observable.StartAsync(actionAsync); Type guard
bool IsValidDelegate<T>(T? d) where T : Delegate => d is not null;
Try / catch
try
{
var xs = Observable.StartAsync(actionAsync);
}
catch (ArgumentNullException ex) when (ex.ParamName == "actionAsync")
{
// log: async delegate was null
} Prevention
- Pass async lambdas inline rather than storing them in nullable fields.
- Validate Func<Task> sources at assignment time.
- Ensure DI registrations exist for async factories.
When it happens
Trigger: Calling Observable.StartAsync(Func<Task>) with a null delegate: an unassigned Func<Task> field, a factory method returning null, or a conditional lambda assignment with a missing branch.
Common situations: Passing a method group whose instance is null, DI/config-resolved delegates that were never registered, or refactorings that moved the async lambda into a nullable property.
Related errors
- Value cannot be null. (Parameter 'onNextAsync')
- Value cannot be null. (Parameter 'onErrorAsync')
- Value cannot be null. (Parameter 'onCompletedAsync')
- nameof(onError)
- nameof(onCompleted)
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/8bc69fbb0b6a1f4c.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs:1281
}
/// <summary>
/// Invokes the asynchronous action, surfacing the result through an observable sequence.
/// </summary>
/// <param name="actionAsync">Asynchronous action to run.</param>
/// <returns>An observable sequence exposing a Unit value upon completion of the action, or an exception.</returns>
/// <exception cref="ArgumentNullException"><paramref name="actionAsync"/> is null.</exception>
/// <remarks>
/// <list type="bullet">
/// <item><description>The action is started immediately, not during the subscription of the resulting sequence.</description></item>
/// <item><description>Multiple subscriptions to the resulting sequence can observe the action's outcome.</description></item>
/// </list>
/// </remarks>
public static IObservable<Unit> StartAsync(Func<Task> actionAsync)
{
if (actionAsync == null)
{
throw new ArgumentNullException(nameof(actionAsync));
}
return s_impl.StartAsync(actionAsync);
}
/// <summary>
/// Invokes the asynchronous action, surfacing the result through an observable sequence.
/// </summary>
/// <param name="actionAsync">Asynchronous action to run.</param>
/// <param name="scheduler">Scheduler on which to notify observers.</param>
/// <returns>An observable sequence exposing a Unit value upon completion of the action, or an exception.</returns>
/// <exception cref="ArgumentNullException"><paramref name="actionAsync"/> is null or <paramref name="scheduler"/> is null.</exception>
/// <remarks>
/// <list type="bullet">
/// <item><description>The action is started immediately, not during the subscription of the resulting sequence.</description></item>
/// <item><description>Multiple subscriptions to the resulting sequence can observe the action's outcome.</description></item>
/// </list>
/// </remarks>View on GitHub (pinned to 94b5d5ab91)