dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'create')
Error message
Value cannot be null. (Parameter 'create')
What it means
TestScheduler.Start<T>(Func<IObservable<T>>, long, long, long) throws ArgumentNullException when the create factory is null. The scheduler needs the factory to create the observable under test at the 'created' virtual time. The message names the parameter ('create').
Solutions
- Pass a non-null factory lambda, e.g. () => Observable.Return(42)
- Fix the builder/helper that supplied the null factory
- Validate the factory with the test framework before calling Start
Example fix
// before Func<IObservable<int>> create = GetFactory(); // null on misconfiguration var observer = scheduler.Start(create, 100, 200, 300); // after Func<IObservable<int>> create = GetFactory() ?? (() => Observable.Empty<int>()); var observer = scheduler.Start(create, 100, 200, 300);
Defensive patterns
Strategy: validation
Validate before calling
if (create == null) throw new InvalidOperationException("Observable factory was not set");
scheduler.Start(create, 100, 200, 300); Type guard
bool HasFactory<T>(Func<IObservable<T>> f) => f is not null;
Try / catch
try { scheduler.Start(create, 100, 200, 300); }
catch (ArgumentNullException ex) when (ex.ParamName == "create")
{
Assert.Fail("Test bug: create factory was null.");
} Prevention
- Pass lambda literals directly to Start when possible
- Initialize factory delegates at declaration
- Avoid nullable delegate fields in test helpers
When it happens
Trigger: Calling scheduler.Start(null, created, subscribed, disposed) or passing a factory variable that is null, e.g. a builder returning null.
Common situations: Test helpers parameterized by an observable factory that was never assigned; conditional test setup that skips factory creation; refactors replacing a lambda with a method group that resolved to null (e.g. an uninitialized delegate field).
Related errors
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/00f03888d0d1f834.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs:88
}
/// <summary>
/// Starts the test scheduler and uses the specified virtual times to invoke the factory function, subscribe to the resulting sequence, and dispose the subscription.
/// </summary>
/// <typeparam name="T">The element type of the observable sequence being tested.</typeparam>
/// <param name="create">Factory method to create an observable sequence.</param>
/// <param name="created">Virtual time at which to invoke the factory to create an observable sequence.</param>
/// <param name="subscribed">Virtual time at which to subscribe to the created observable sequence.</param>
/// <param name="disposed">Virtual time at which to dispose the subscription.</param>
/// <returns>Observer with timestamped recordings of notification messages that were received during the virtual time window when the subscription to the source sequence was active.</returns>
/// <exception cref="ArgumentNullException"><paramref name="create"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="subscribed"/> is less than <paramref name="created"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="disposed"/> is less than <paramref name="created"/> or <paramref name="subscribed"/>.</exception>
public ITestableObserver<T> Start<T>(Func<IObservable<T>> create, long created, long subscribed, long disposed)
{
if (create == null)
{
throw new ArgumentNullException(nameof(create));
}
if (subscribed < created)
{
throw new ArgumentOutOfRangeException(nameof(subscribed));
}
if (disposed < created || disposed < subscribed)
{
throw new ArgumentOutOfRangeException(nameof(disposed));
}
var source = default(IObservable<T>);
var subscription = default(IDisposable);
var observer = CreateObserver<T>();
ScheduleAbsolute(default(object), created, (scheduler, state) => { source = create(); return Disposable.Empty; });
ScheduleAbsolute(default(object), subscribed, (scheduler, state) => { subscription = source.Subscribe(observer); return Disposable.Empty; });
ScheduleAbsolute(default(object), disposed, (scheduler, state) => { subscription.Dispose(); return Disposable.Empty; });View on GitHub (pinned to 94b5d5ab91)