{"record":{"id":"9fef000cc89b8e95","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-9fef00","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'retryCount')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'retryCount'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/Retry.cs","lineNumber":38,"sourceCode":"                throw new ArgumentNullException(nameof(source));\n\n            return new[] { source }.Repeat().Catch();\n        }\n\n        /// <summary>\n        /// Creates a sequence that retries enumerating the source sequence as long as an error occurs, with the specified\n        /// maximum number of retries.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"retryCount\">Maximum number of retries.</param>\n        /// <returns>Sequence concatenating the results of the source sequence as long as an error occurs.</returns>\n        public static IEnumerable<TSource> Retry<TSource>(this IEnumerable<TSource> source, int retryCount)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (retryCount < 0)\n                throw new ArgumentOutOfRangeException(nameof(retryCount));\n\n            return new[] { source }.Repeat(retryCount).Catch();\n        }\n    }\n}\n","sourceCodeStart":20,"sourceCodeEnd":44,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Retry.cs#L20-L44","documentation":"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.","triggerScenarios":"Calling Retry(source, -1) or a negative count computed from user input, config, or arithmetic (e.g. remaining = budget - spent going negative).","commonSituations":"Retry limits read from app settings without validation; off-by-one arithmetic producing -1; defaults not initialized.","solutions":["Validate retryCount >= 0 before calling","Clamp with Math.Max(0, retryCount)","Sanitize config/user input that supplies the retry limit"],"exampleFix":"// before\nvar result = source.Retry(retries);\n// after\nvar result = source.Retry(Math.Max(0, retries));","handlingStrategy":"validation","validationCode":"if (retryCount < 0) throw new ArgumentOutOfRangeException(nameof(retryCount));\nvar result = source.Retry(Math.Max(0, retryCount));","typeGuard":null,"tryCatchPattern":"try { var result = source.Retry(retryCount); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"retryCount\") { /* clamp or report invalid setting */ }","preventionTips":["Validate retry limits from settings/user input","Clamp with Math.Max(0, n)","Initialize retry-count defaults explicitly"],"tags":["csharp","linq","argument-out-of-range","ix-net"],"backgroundTag":"argument-out-of-range","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}