dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'source')
Error message
Value cannot be null. (Parameter 'source')
What it means
The Catch operator overload Catch<TSource,TException>(source, handler) throws ArgumentNullException with parameter name 'source' when the source sequence is null. Ix.NET validates arguments eagerly so nulls are reported at the point of the call. The handler parameter must also be non-null or a separate error for 'handler' is thrown.
Solutions
- Ensure the source is non-null; use Enumerable.Empty<TSource>() when there is no data.
- Coalesce at the call site: (source ?? Enumerable.Empty<T>()).Catch(handler).
- Fix the upstream method to return an empty sequence rather than null.
- Enable nullable reference types so the compiler warns before the call.
Example fix
// before var result = possiblyNullSource.Catch<MyException>(ex => fallback); // after var result = (possiblyNullSource ?? Enumerable.Empty<int>()).Catch<MyException>(ex => fallback);
Defensive patterns
Strategy: validation
Validate before calling
if (source is null)
throw new ArgumentNullException(nameof(source));
// or coalesce at the call site:
var result = (source ?? Enumerable.Empty<TSource>()).Catch(handler); Type guard
static bool IsUsableSource<TSource>(IEnumerable<TSource> s) => s != null;
Try / catch
try
{
var result = source.Catch<MyException>(handler);
}
catch (ArgumentNullException ex) when (ex.ParamName == "source")
{
var result = Enumerable.Empty<TSource>();
} Prevention
- Never use nullable sequence fields directly as operator receivers; coalesce with ?? Enumerable.Empty<T>().
- Make upstream APIs return empty sequences instead of null.
- Enable nullable reference types to catch null receivers at compile time.
- Check extension-method receivers for null before chaining operator pipelines.
When it happens
Trigger: Calling source.Catch<TException>(handler) where the receiver sequence is null, e.g. a method returned null instead of an empty sequence.
Common situations: Chaining operators on a repository method's result that can return null; using a nullable field directly as the source; interop with APIs that use null to mean 'no data'.
Related errors
- Value cannot be null. (Parameter 'defaultSource')
- Value cannot be null. (Parameter 'handler')
- Value cannot be null. (Parameter 'sources')
- 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/e44698c27f36fcbc.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs:24
namespace System.Linq
{
public static partial class EnumerableEx
{
/// <summary>
/// Creates a sequence that corresponds to the source sequence, concatenating it with the sequence resulting from
/// calling an exception handler function in case of an error.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <typeparam name="TException">Exception type to catch.</typeparam>
/// <param name="source">Source sequence.</param>
/// <param name="handler">Handler to invoke when an exception of the specified type occurs.</param>
/// <returns>Source sequence, concatenated with an exception handler result sequence in case of an error.</returns>
public static IEnumerable<TSource> Catch<TSource, TException>(this IEnumerable<TSource> source, Func<TException, IEnumerable<TSource>> handler)
where TException : Exception
{
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);View on GitHub (pinned to 94b5d5ab91)