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
IgnoreElements enumerates a sequence and discards all of its elements, yielding nothing. Because the argument is validated eagerly in the public operator, passing a null source throws ArgumentNullException with paramName 'source' immediately rather than on MoveNext.
Solutions
- Verify the source expression is non-null before invoking IgnoreElements; fix the producer so it returns an empty sequence instead of null.
- Coalesce with ?? Enumerable.Empty<TSource>() at the call site.
- If null signals a real problem, check and throw/log before calling, so the failure is attributable to the actual cause.
Example fix
// before items.IgnoreElements().Run(); // items is null when the cache missed // after (items ?? Enumerable.Empty<Item>()).IgnoreElements().Run();
Defensive patterns
Strategy: validation
Validate before calling
if (source is null) source = Enumerable.Empty<TSource>(); source.IgnoreElements();
Type guard
static bool HasSource<T>(IEnumerable<T>? s) => s is not null;
Try / catch
try
{
source.IgnoreElements();
}
catch (ArgumentNullException ex) when (ex.ParamName == "source")
{
// source was null; log and continue with nothing to drain
} Prevention
- Coalesce nullable sources with ?? Enumerable.Empty<T>() before chaining Ix operators
- Fix producers to return empty sequences, never null, for 'no data'
- Enable nullable reference types to catch unassigned source variables
When it happens
Trigger: Calling source.IgnoreElements() (extension method on IEnumerable<TSource>) where source is null, e.g. someQuery.IgnoreElements() when someQuery came from a null-returning factory or deserialization.
Common situations: Chaining Ix operators onto results of methods that may return null (configuration lookups, optional service calls); using IgnoreElements purely for side effects (e.g. draining an observable-like source) where the source variable was never assigned.
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/90e74a9a2b189d0d.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/IgnoreElements.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>
/// Ignores all elements in the source sequence.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="source">Source sequence.</param>
/// <returns>Source sequence without its elements.</returns>
public static IEnumerable<TSource> IgnoreElements<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
return IgnoreElementsCore(source);
}
private static IEnumerable<TSource> IgnoreElementsCore<TSource>(IEnumerable<TSource> source)
{
foreach (var _ in source)
;
yield break;
}
}
}
View on GitHub (pinned to 94b5d5ab91)