dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'sources')
Error message
Value cannot be null. (Parameter 'sources')
What it means
The params overload OnErrorResumeNext(params IEnumerable<TSource>[] sources) throws ArgumentNullException when the sources array itself is null. This is eager argument validation so failure occurs at call time, not during enumeration.
Solutions
- Pass an initialized array; use an empty array if there are no sequences.
- Coalesce with a fallback: sources ?? new IEnumerable<int>[0].
- Fix the upstream builder that produced a null array.
Example fix
// before var combined = xs.OnErrorResumeNext(seqArray); // seqArray may be null // after var combined = xs.OnErrorResumeNext(seqArray ?? new IEnumerable<int>[0]);
Defensive patterns
Strategy: validation
Validate before calling
if (sources == null) sources = Array.Empty<IEnumerable<int>>(); var combined = xs.OnErrorResumeNext(sources);
Type guard
static bool HasSources(IEnumerable<int>[]? sources) => sources is { Length: > 0 }; Try / catch
try
{
var combined = xs.OnErrorResumeNext(sources);
}
catch (ArgumentNullException ex) when (ex.ParamName == "sources")
{
// handle missing array
} Prevention
- Initialize sequence arrays with Array.Empty<T>() instead of leaving them null.
- Prefer the IEnumerable<IEnumerable<T>> overload with an empty sequence over params with null.
- Validate dynamically-built arrays before passing them on.
When it happens
Trigger: Calling OnErrorResumeNext((IEnumerable<int>[])null) or passing a null array variable into the params overload.
Common situations: Building an array of sequences dynamically (e.g. from a collection of tasks or files) where the array was never initialized.
Related errors
- ArgumentNullException(nameof(comparer))
- Value cannot be null. (Parameter 'second')
- Value cannot be null. (Parameter 'source')
- Value cannot be null. (Parameter 'selector')
- Value cannot be null. (Parameter 'source')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/3148498f47fba528.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/OnErrorResumeNext.cs:38
if (first == null)
throw new ArgumentNullException(nameof(first));
if (second == null)
throw new ArgumentNullException(nameof(second));
return OnErrorResumeNextCore(new[] { first, second });
}
/// <summary>
/// Creates a sequence that concatenates the given sequences, regardless of whether an error occurs in any of the
/// sequences.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="sources">Source sequences.</param>
/// <returns>Sequence concatenating the elements of the given sequences, ignoring errors.</returns>
public static IEnumerable<TSource> OnErrorResumeNext<TSource>(params IEnumerable<TSource>[] sources)
{
if (sources == null)
throw new ArgumentNullException(nameof(sources));
return OnErrorResumeNextCore(sources);
}
/// <summary>
/// Creates a sequence that concatenates the given sequences, regardless of whether an error occurs in any of the
/// sequences.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="sources">Source sequences.</param>
/// <returns>Sequence concatenating the elements of the given sequences, ignoring errors.</returns>
public static IEnumerable<TSource> OnErrorResumeNext<TSource>(this IEnumerable<IEnumerable<TSource>> sources)
{
if (sources == null)
throw new ArgumentNullException(nameof(sources));
return OnErrorResumeNextCore(sources);
}View on GitHub (pinned to 94b5d5ab91)