dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'second')
Error message
Value cannot be null. (Parameter 'second')
What it means
OnErrorResumeNext(first, second) throws ArgumentNullException when the 'second' sequence is null. The library validates arguments eagerly so a bad call fails immediately rather than producing a confusing failure during deferred enumeration.
Solutions
- Pass a non-null second sequence; use Enumerable.Empty<TSource>() when there is nothing to concatenate.
- Check the producing code path (config/lookup) that yielded a null sequence and fix it.
- If null means 'no extra sequences', guard the call site: second != null ? src.OnErrorResumeNext(second) : src.
Example fix
// before var combined = first.OnErrorResumeNext(second); // second may be null // after var combined = first.OnErrorResumeNext(second ?? Enumerable.Empty<int>());
Defensive patterns
Strategy: validation
Validate before calling
if (second == null) throw new InvalidOperationException("second sequence must not be null");
var combined = first.OnErrorResumeNext(second); Type guard
static bool HasSecond(IEnumerable<int>? second) => second is not null;
Try / catch
try
{
var combined = first.OnErrorResumeNext(second);
}
catch (ArgumentNullException ex) when (ex.ParamName == "second")
{
// handle missing sequence
} Prevention
- Default nullable sequence parameters to Enumerable.Empty<T>() at boundaries.
- Enable nullable reference types so null flows are caught at compile time.
- Never pass results of lookups that can return null directly into operator overloads.
When it happens
Trigger: Calling Enumerable.OnErrorResumeNext(first, null) where the second IEnumerable<TSource> parameter is null.
Common situations: Passing a sequence returned from a method that can return null (e.g. a lookup or dictionary miss), or chaining sequences where one source was conditionally built and left null.
Related errors
- ArgumentNullException(nameof(comparer))
- Value cannot be null. (Parameter 'sources')
- 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/2bec72b776eddf4d.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/OnErrorResumeNext.cs:23
using System.Collections.Generic;
namespace System.Linq
{
public static partial class EnumerableEx
{
/// <summary>
/// Creates a sequence that concatenates both given sequences, regardless of whether an error occurs.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="first">First sequence.</param>
/// <param name="second">Second sequence.</param>
/// <returns>Sequence concatenating the elements of both sequences, ignoring errors.</returns>
public static IEnumerable<TSource> OnErrorResumeNext<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
{
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);
}View on GitHub (pinned to 94b5d5ab91)