dotnet/reactive · error · ArgumentNullException
actionAsync
Error message
actionAsync
What it means
StartAsync(Func<Task>, IAsyncScheduler) throws ArgumentNullException when the actionAsync delegate is null. The operator invokes the delegate immediately to obtain the Task representing the work, so a null delegate is rejected during argument validation.
Solutions
- Pass a non-null Func<Task>
- Guard the call site if the handler is optional
- Initialize the delegate before invoking StartAsync
Example fix
// before StartAsync(handler); // handler is null // after if (handler != null) StartAsync(handler);
Defensive patterns
Strategy: validation
Validate before calling
if (actionAsync == null) throw new ArgumentNullException(nameof(actionAsync));
Type guard
static bool IsValidActionAsync(Func<Task> f) => f is not null;
Prevention
- Guard nullable async handlers before passing to StartAsync
- Prefer initializing handlers to async no-ops over leaving them null
When it happens
Trigger: Calling the Unit-returning StartAsync overload for Task-returning functions with a null Func<Task>.
Common situations: Unassigned async handler fields, factory/lookup returning null, refactoring that removed the actual handler.
Related errors
- null (Parameter 'scheduler')
- null (Parameter 'values')
- action
- functionAsync
- Value cannot be null. (Parameter 'onErrorAsync')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/b3b3b3197cc5287d.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/StartAsync.cs:72
catch (Exception ex)
{
return Throw<TSource>(ex);
}
return Create<TSource>(async observer =>
{
var subscription = await task.ToAsyncObservable(scheduler).SubscribeAsync(observer).ConfigureAwait(false);
return StableCompositeAsyncDisposable.Create(cancel, subscription);
});
}
public static IAsyncObservable<Unit> StartAsync(Func<Task> actionAsync) => StartAsync(actionAsync, ImmediateAsyncScheduler.Instance);
public static IAsyncObservable<Unit> StartAsync(Func<Task> actionAsync, IAsyncScheduler scheduler)
{
if (actionAsync == null)
throw new ArgumentNullException(nameof(actionAsync));
if (scheduler == null)
throw new ArgumentNullException(nameof(scheduler));
Task task;
try
{
task = actionAsync();
}
catch (Exception ex)
{
return Throw<Unit>(ex);
}
return task.ToAsyncObservable(scheduler);
}
public static IAsyncObservable<Unit> StartAsync(Func<CancellationToken, Task> actionAsync) => StartAsync(actionAsync, ImmediateAsyncScheduler.Instance);View on GitHub (pinned to 94b5d5ab91)