dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'sources')
Error message
Value cannot be null. (Parameter 'sources')
What it means
The Catch overload taking a sequence of sequences, Catch<TSource>(IEnumerable<IEnumerable<TSource>> sources), throws ArgumentNullException with parameter name 'sources' when the outer sequence is null. The library requires a (possibly empty) container of sequences; null is rejected eagerly at call time.
Solutions
- Pass a non-null enumerable; use an empty sequence if there are no candidates.
- Coalesce at the call site: (sources ?? Enumerable.Empty<IEnumerable<T>>()).Catch().
- Fix the producer to return Enumerable.Empty<IEnumerable<T>>() instead of null.
- Enable nullable reference types to catch it at compile time.
Example fix
// before var result = ((List<IEnumerable<int>>)null).Catch(); // after var result = (sources ?? Enumerable.Empty<IEnumerable<int>>()).Catch();
Defensive patterns
Strategy: validation
Validate before calling
if (sources is null)
throw new ArgumentNullException(nameof(sources));
// or coalesce:
sources ??= Enumerable.Empty<IEnumerable<TSource>>(); Type guard
static bool IsUsableSources<TSource>(IEnumerable<IEnumerable<TSource>> s) => s != null;
Try / catch
try
{
var result = sources.Catch();
}
catch (ArgumentNullException ex) when (ex.ParamName == "sources")
{
var result = Enumerable.Empty<TSource>();
} Prevention
- Producers of collections should return empty sequences, never null.
- Coalesce nullable outer enumerables before passing to operators.
- Enable nullable reference types to catch null arguments at compile time.
- Be careful with deserialization: configure it to emit empty collections instead of null.
When it happens
Trigger: Calling Catch<TSource>(sources) with a null outer enumerable, e.g. a list of retry attempts built elsewhere that was never assigned.
Common situations: A factory method returning null instead of an empty list; LINQ result of a nullable source without coalescing; deserialization producing null for an empty collection.
Related errors
- Value cannot be null. (Parameter 'defaultSource')
- Value cannot be null. (Parameter 'source')
- Value cannot be null. (Parameter 'handler')
- Value cannot be null. (Parameter 'first')
- Value cannot be null. (Parameter 'second')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/9ec5bd26ca238a95.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs:40
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (handler == null)
throw new ArgumentNullException(nameof(handler));
return CatchCore(source, handler);
}
/// <summary>
/// Creates a sequence by concatenating source sequences until a source sequence completes successfully.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="sources">Source sequences.</param>
/// <returns>Sequence that continues to concatenate source sequences while errors occur.</returns>
public static IEnumerable<TSource> Catch<TSource>(this IEnumerable<IEnumerable<TSource>> sources)
{
if (sources == null)
throw new ArgumentNullException(nameof(sources));
return CatchCore(sources);
}
/// <summary>
/// Creates a sequence by concatenating source sequences until a source sequence completes successfully.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="sources">Source sequences.</param>
/// <returns>Sequence that continues to concatenate source sequences while errors occur.</returns>
public static IEnumerable<TSource> Catch<TSource>(params IEnumerable<TSource>[] sources)
{
if (sources == null)
throw new ArgumentNullException(nameof(sources));
return CatchCore(sources);
}
View on GitHub (pinned to 94b5d5ab91)