dotnet/reactive · error · ArgumentOutOfRangeException
Specified argument was out of the range of valid values…
Error message
Specified argument was out of the range of valid values. (Parameter 'retryCount')
What it means
The Retry(retryCount) overload validates that retryCount is non-negative; the generic ArgumentOutOfRangeException fires for parameter 'retryCount' when it is negative. Fix: pass 0 or a positive retry limit.
Solutions
- Validate retryCount >= 0 before calling
- Clamp with Math.Max(0, retryCount)
- Sanitize config/user input that supplies the retry limit
Example fix
// before var result = source.Retry(retries); // after var result = source.Retry(Math.Max(0, retries));
Defensive patterns
Strategy: validation
Validate before calling
if (retryCount < 0) throw new ArgumentOutOfRangeException(nameof(retryCount)); var result = source.Retry(Math.Max(0, retryCount));
Try / catch
try { var result = source.Retry(retryCount); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "retryCount") { /* clamp or report invalid setting */ } Prevention
- Validate retry limits from settings/user input
- Clamp with Math.Max(0, n)
- Initialize retry-count defaults explicitly
When it happens
Trigger: Calling Retry(source, -1) or a negative count computed from user input, config, or arithmetic (e.g. remaining = budget - spent going negative).
Common situations: Retry limits read from app settings without validation; off-by-one arithmetic producing -1; defaults not initialized.
Related errors
- Specified argument was out of the range of valid values…
- Value cannot be null. (Parameter 'accumulator')
- Value cannot be null. (Parameter 'comparer')
- Value cannot be null. (Parameter 'defaultSource')
- Value cannot be null. (Parameter 'first')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/9fef000cc89b8e95.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/Retry.cs:38
throw new ArgumentNullException(nameof(source));
return new[] { source }.Repeat().Catch();
}
/// <summary>
/// Creates a sequence that retries enumerating the source sequence as long as an error occurs, with the specified
/// maximum number of retries.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="source">Source sequence.</param>
/// <param name="retryCount">Maximum number of retries.</param>
/// <returns>Sequence concatenating the results of the source sequence as long as an error occurs.</returns>
public static IEnumerable<TSource> Retry<TSource>(this IEnumerable<TSource> source, int retryCount)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (retryCount < 0)
throw new ArgumentOutOfRangeException(nameof(retryCount));
return new[] { source }.Repeat(retryCount).Catch();
}
}
}
View on GitHub (pinned to 94b5d5ab91)