dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'getEnumerator')
Error message
Value cannot be null. (Parameter 'getEnumerator')
What it means
System.Interactive's Create operator builds an IEnumerable from a factory delegate that produces an IEnumerator on each enumeration. The library eagerly validates its arguments and throws ArgumentNullException when the getEnumerator factory is null, so the failure surfaces at call time rather than at enumeration time.
Solutions
- Ensure the delegate passed to Create (or to Memoize/Publish/Share whose argument is forwarded) is non-null before calling
- Fix whatever produces the null factory — e.g. a factory dictionary or switch that returns null for the given key
- If the factory is conditionally unavailable, throw a more descriptive exception or fall back to an empty sequence
- Wrap the call in a null-coalescing expression: Create(() => ?? throw new InvalidOperationException(...))
Example fix
// before
var seq = EnumerableEx.Create(getEnumerator); // getEnumerator is null
// after
if (getEnumerator == null)
throw new InvalidOperationException("No enumerator factory configured for this source.");
var seq = EnumerableEx.Create(getEnumerator); Defensive patterns
Strategy: validation
Validate before calling
if (getEnumerator == null)
throw new ArgumentNullException(nameof(getEnumerator));
// or defensively:
var factory = getEnumerator ?? throw new ArgumentException("Enumerator factory must be provided.");
var seq = EnumerableEx.Create(factory); Type guard
static bool IsValidFactory<T>(Func<IEnumerator<T>> factory) => factory is not null;
Try / catch
try
{
var seq = EnumerableEx.Create(getEnumerator);
}
catch (ArgumentNullException ex) when (ex.ParamName == "getEnumerator")
{
// log and supply a default factory or rethrow with context
} Prevention
- Never return null delegates from factory-lookup code; throw or return a default instead
- Use throw expressions in switch/map lookups so missing keys fail loudly
- Enable nullable reference types so unassigned delegate variables are flagged at compile time
When it happens
Trigger: Calling EnumerableEx.Create<TResult>(null) directly, or calling Memoize/Publish/Share with a null source or a null enumerator-factory argument that they forward to Create.
Common situations: A factory method returning null instead of a delegate (e.g. a switch statement that misses a default branch), a config-driven delegate lookup that resolves to null, or passing an uninitialized method-group variable.
Related errors
- Value cannot be null. (Parameter 'create')
- Value cannot be null. (Parameter 'defaultSource')
- Value cannot be null. (Parameter 'first')
- Value cannot be null. (Parameter 'handler')
- Value cannot be null. (Parameter 'second')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/40b0647aee946ba6.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/Create.cs:21
// See the LICENSE file in the project root for more information.
using System.Collections;
using System.Collections.Generic;
namespace System.Linq
{
public static partial class EnumerableEx
{
/// <summary>
/// Creates an enumerable sequence based on an enumerator factory function.
/// </summary>
/// <typeparam name="TResult">Result sequence element type.</typeparam>
/// <param name="getEnumerator">Enumerator factory function.</param>
/// <returns>Sequence that will invoke the enumerator factory upon a call to GetEnumerator.</returns>
public static IEnumerable<TResult> Create<TResult>(Func<IEnumerator<TResult>> getEnumerator)
{
if (getEnumerator == null)
throw new ArgumentNullException(nameof(getEnumerator));
return new AnonymousEnumerable<TResult>(getEnumerator);
}
/// <summary>
/// Creates an enumerable sequence based on an asynchronous method that provides a yielder.
/// </summary>
/// <typeparam name="T">Result sequence element type.</typeparam>
/// <param name="create">
/// Delegate implementing an asynchronous method that can use the specified yielder to yield return
/// values.
/// </param>
/// <returns>Sequence that will use the asynchronous method to obtain its elements.</returns>
public static IEnumerable<T> Create<T>(Action<IYielder<T>> create)
{
if (create == null)
throw new ArgumentNullException(nameof(create));
View on GitHub (pinned to 94b5d5ab91)