dotnet/reactive · error · ArgumentNullException
function
Error message
function
What it means
Start throws ArgumentNullException when the function argument is null. Start converts a synchronous Func<TSource> into an async observable and invokes it (via ToAsync) on a scheduler, so it requires a real delegate to execute.
Solutions
- Pass a valid Func<TSource>, e.g. () => ComputeValue()
- Null-check the function variable before calling Start
- Fix the code path that was supposed to assign the function
Example fix
// before Func<int> fn = null; var obs = AsyncObservable.Start(fn); // after var obs = AsyncObservable.Start(() => ComputeValue());
Defensive patterns
Strategy: validation
Validate before calling
if (function == null) throw new ArgumentNullException(nameof(function));
Type guard
bool IsValid<TSource>(Func<TSource> f) => f != null;
Try / catch
try { var obs = AsyncObservable.Start(fn); }
catch (ArgumentNullException ex) when (ex.ParamName == "function") { /* supply function */ } Prevention
- Pass inline lambdas to Start rather than nullable delegate variables
- Enable NRT so unassigned Func fields are compile-time warnings
When it happens
Trigger: Calling AsyncObservable.Start<TSource>((Func<TSource>)null).
Common situations: A delegate field or config-selected function was never assigned; passing a null Action/Func variable created for conditional execution.
Related errors
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/6473ba90c9020fd6.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/Start.cs:14
// 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;
namespace System.Reactive.Linq
{
public partial class AsyncObservable
{
public static IAsyncObservable<TSource> Start<TSource>(Func<TSource> function)
{
if (function == null)
throw new ArgumentNullException(nameof(function));
return ToAsync(function)();
}
public static IAsyncObservable<TSource> Start<TSource>(Func<TSource> function, IAsyncScheduler scheduler)
{
if (function == null)
throw new ArgumentNullException(nameof(function));
if (scheduler == null)
throw new ArgumentNullException(nameof(scheduler));
return ToAsync(function, scheduler)();
}
public static IAsyncObservable<Unit> Start(Action action)
{
if (action == null)
throw new ArgumentNullException(nameof(action));View on GitHub (pinned to 94b5d5ab91)