dotnet/reactive · error · ArgumentNullException
Thrown when source is null (ArgumentNullException, param…
Error message
Thrown when source is null (ArgumentNullException, param name: source)
What it means
IsEmpty checks whether a sequence contains no elements by delegating to Any(). The operator validates its argument eagerly, so a null source throws ArgumentNullException with paramName 'source' at the call site rather than during evaluation.
Solutions
- Null-check the source first: if (data != null && data.IsEmpty()).
- Coalesce to an empty sequence: (data ?? []).IsEmpty().
- Fix the upstream producer to return an empty collection instead of null for the 'none' case.
Example fix
// before if (results.IsEmpty()) ShowEmpty(); // results may be null // after if (results is not null && results.IsEmpty()) ShowEmpty();
Defensive patterns
Strategy: validation
Validate before calling
bool empty = source is not null && source.IsEmpty();
Type guard
static bool IsNullOrEmpty<T>(IEnumerable<T>? s) => s is null || s.IsEmpty();
Try / catch
try
{
var empty = source.IsEmpty();
}
catch (ArgumentNullException ex) when (ex.ParamName == "source")
{
var empty = true; // treat null as empty
} Prevention
- Write null-safe emptiness checks as a helper (IsNullOrEmpty)
- Treat null and empty distinctly at the domain boundary, then normalize to empty
- Don't feed nullable API results straight into IsEmpty/Any-style guards
When it happens
Trigger: Calling source.IsEmpty() where source is null, e.g. bool empty = ParseList(xml).IsEmpty() when ParseList can return null.
Common situations: Guard checks written as if (data.IsEmpty()) where data came from an API returning null for 'no data'; migrating code from LINQ's Any() (which also throws on null) to Ix's IsEmpty without adding null handling.
Related errors
- Thrown when source is null (ArgumentNullException, param…
- Thrown when source is null (ArgumentNullException, param…
- Thrown when comparer is null (ArgumentNullException, param…
- Thrown when source is null (ArgumentNullException, param…
- Thrown when keySelector is null (ArgumentNullException…
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/b35edac6b2474f76.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/IsEmpty.cs:20
// The .NET Foundation licenses this file to you under the MIT License.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
namespace System.Linq
{
public static partial class EnumerableEx
{
/// <summary>
/// Determines whether an enumerable sequence is empty.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="source">Source sequence.</param>
/// <returns>true if the sequence is empty; false otherwise.</returns>
public static bool IsEmpty<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
return !source.Any();
}
}
}
View on GitHub (pinned to 94b5d5ab91)