dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'messages')
Error message
Value cannot be null. (Parameter 'messages')
What it means
TestScheduler.CreateHotObservable throws ArgumentNullException when the messages array parameter is null. It builds a HotObservable that replays Recorded<Notification<T>> marble messages; a null message list cannot represent a valid sequence, so it is rejected before construction. Note an empty array is allowed (a hot observable that never emits).
Solutions
- Pass at least an empty array instead of null: CreateHotObservable<int>()
- Fix the array-producing helper to return Array.Empty<Recorded<Notification<int>>>() when there are no messages
- Null-check parsed marble input before constructing the observable
Example fix
// before var xs = scheduler.CreateHotObservable<int>(ParseMarbles(null)); // null array // after var msgs = ParseMarbles(marbleString) ?? Array.Empty<Recorded<Notification<int>>>(); var xs = scheduler.CreateHotObservable(msgs);
Defensive patterns
Strategy: validation
Validate before calling
// C#
Recorded<Notification<int>>[]? msgs = BuildMessages(marble);
if (msgs is null)
msgs = Array.Empty<Recorded<Notification<int>>>();
var xs = scheduler.CreateHotObservable(msgs); Type guard
bool HasMessages<T>(Recorded<Notification<T>>[]? m) => m is not null;
Try / catch
try { var xs = scheduler.CreateHotObservable(msgs); }
catch (ArgumentNullException ex) when (ex.ParamName == "messages")
{
xs = scheduler.CreateHotObservable<T>(); // empty hot observable
} Prevention
- Call CreateHotObservable<T>() with no args instead of null for empty sequences
- Ensure marble-string parsers return Array.Empty rather than null
- Non-nullable array types in test helpers
When it happens
Trigger: Calling scheduler.CreateHotObservable<T>(null) explicitly, or passing a Recorded<Notification<T>>[] variable that is null (e.g. from a failed lookup or deserialization), while an empty params list is fine.
Common situations: Marble-test helpers that build message arrays dynamically and return null on parse failure; data-driven tests with null entries; refactors converting marble-string parsers to array builders that leave null results.
Related errors
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/f1164244a445a050.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs:161
{
throw new ArgumentNullException(nameof(create));
}
return Start(create, ReactiveTest.Created, ReactiveTest.Subscribed, ReactiveTest.Disposed);
}
/// <summary>
/// Creates a hot observable using the specified timestamped notification messages.
/// </summary>
/// <typeparam name="T">The element type of the observable sequence being created.</typeparam>
/// <param name="messages">Notifications to surface through the created sequence at their specified absolute virtual times.</param>
/// <returns>Hot observable sequence that can be used to assert the timing of subscriptions and notifications.</returns>
/// <exception cref="ArgumentNullException"><paramref name="messages"/> is null.</exception>
public ITestableObservable<T> CreateHotObservable<T>(params Recorded<Notification<T>>[] messages)
{
if (messages == null)
{
throw new ArgumentNullException(nameof(messages));
}
return new HotObservable<T>(this, messages);
}
/// <summary>
/// Creates a cold observable using the specified timestamped notification messages.
/// </summary>
/// <typeparam name="T">The element type of the observable sequence being created.</typeparam>
/// <param name="messages">Notifications to surface through the created sequence at their specified virtual time offsets from the sequence subscription time.</param>
/// <returns>Cold observable sequence that can be used to assert the timing of subscriptions and notifications.</returns>
/// <exception cref="ArgumentNullException"><paramref name="messages"/> is null.</exception>
public ITestableObservable<T> CreateColdObservable<T>(params Recorded<Notification<T>>[] messages)
{
if (messages == null)
{
throw new ArgumentNullException(nameof(messages));
}View on GitHub (pinned to 94b5d5ab91)