dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'source')
Error message
Value cannot be null. (Parameter 'source')
What it means
Repeat(source) throws ArgumentNullException when the source sequence is null. Repeat concatenates the source to itself (infinitely or N times), which requires a valid source; the argument is validated eagerly at call time.
Solutions
- Pass a non-null source; substitute Enumerable.Empty<TSource>() when there is nothing to repeat (note: an empty source repeats infinitely to nothing).
- Coalesce: (source ?? Enumerable.Empty<T>()).Repeat().
- Fix the upstream producer that returned a null sequence.
Example fix
// before var repeated = source.Repeat(); // source may be null // after var repeated = (source ?? Enumerable.Empty<int>()).Repeat();
Defensive patterns
Strategy: validation
Validate before calling
if (source == null) source = Enumerable.Empty<int>(); var repeated = source.Repeat();
Type guard
static bool CanRepeat(IEnumerable<int>? source) => source is not null;
Try / catch
try
{
var repeated = source.Repeat();
}
catch (ArgumentNullException ex) when (ex.ParamName == "source")
{
// handle missing source
} Prevention
- Coalesce nullable sequences to Enumerable.Empty<T>() before repeating.
- Use nullable reference types to catch null sources at compile time.
- Avoid passing results of nullable-returning lookups directly into Repeat.
When it happens
Trigger: Calling Repeat() on a null IEnumerable<TSource>, e.g. source.Repeat() where source came from a nullable producer.
Common situations: Passing a nullable collection from configuration, deserialization, or a lookup straight into Repeat without a null check.
Related errors
- ArgumentNullException(nameof(comparer))
- Value cannot be null. (Parameter 'second')
- Value cannot be null. (Parameter 'sources')
- Value cannot be null. (Parameter 'source')
- Value cannot be null. (Parameter 'selector')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/8d657745d855df72.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/Repeat.cs:46
/// <typeparam name="TResult">Result sequence element type.</typeparam>
/// <param name="element">The value to be repeated.</param>
/// <param name="count">The number of times to repeat the value in the generated sequence.</param>
/// <returns>Sequence that contains a repeated value.</returns>
public static IEnumerable<TResult> Repeat<TResult>(TResult element, int count)
{
return Enumerable.Repeat(element, count);
}
/// <summary>
/// Repeats and concatenates the source sequence infinitely.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="source">Source sequence.</param>
/// <returns>Sequence obtained by concatenating the source sequence to itself infinitely.</returns>
public static IEnumerable<TSource> Repeat<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
return RepeatCore(source);
}
/// <summary>
/// Repeats and concatenates the source sequence the given number of times.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="source">Source sequence.</param>
/// <param name="count">Number of times to repeat the source sequence.</param>
/// <returns>Sequence obtained by concatenating the source sequence to itself the specified number of times.</returns>
public static IEnumerable<TSource> Repeat<TSource>(this IEnumerable<TSource> source, int count)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (count < 0)
{View on GitHub (pinned to 94b5d5ab91)