{"record":{"id":"4a73d9830fa3f7f5","repo":"dotnet/reactive","slug":"throw-new-argumentoutofrangeexception-nameof-retrycount","errorCode":null,"errorMessage":"throw new ArgumentOutOfRangeException(nameof(retryCount));","messagePattern":"throw new ArgumentOutOfRangeException\\(nameof\\(retryCount\\)\\);","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Retry.cs","lineNumber":34,"sourceCode":"\n            return Create(\n                source,\n                async static (source, observer) =>\n                {\n                    var (sink, inner) = AsyncObserver.Retry(observer, source);\n\n                    var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, inner);\n                });\n        }\n\n        public static IAsyncObservable<TSource> Retry<TSource>(this IAsyncObservable<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 CreateAsyncObservable<TSource>.From(\n                source,\n                retryCount,\n                static async (source, retryCount, observer) =>\n                {\n                    var (sink, inner) = AsyncObserver.Retry(observer, source, retryCount);\n\n                    var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, inner);\n                });\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static (IAsyncObserver<TSource>, IAsyncDisposable) Retry<TSource>(IAsyncObserver<TSource> observer, IAsyncObservable<TSource> source)","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Retry.cs#L16-L52","documentation":"The Retry(source, retryCount) overload validates retryCount and throws ArgumentOutOfRangeException when it is negative. retryCount bounds the number of re-subscription attempts; a negative count is meaningless so the guard rejects it (after the source null check).","triggerScenarios":"Calling AsyncObservable.Retry(source, retryCount) with retryCount < 0, e.g. a configured attempts value of -1 intended as 'retry forever', or a computed remaining-attempts counter that went negative.","commonSituations":"Using -1 for 'infinite retries' (a convention from other libraries); config values like maxRetries=-1; decrementing a counter below zero before passing it in.","solutions":["Use Retry(source) without a count for infinite retries, or pass a non-negative count.","Clamp: retryCount = Math.Max(0, attempts).","Validate maxRetries at config load, rejecting negatives with a clear message."],"exampleFix":"// before\nvar retried = AsyncObservable.Retry(source, retryCount: -1); // -1 meant 'infinite'\n// after\nvar retried = AsyncObservable.Retry(source); // infinite retries","handlingStrategy":"validation","validationCode":"if (retryCount < 0) throw new ArgumentException(\"retryCount must be >= 0\", nameof(retryCount));","typeGuard":null,"tryCatchPattern":"try { var retried = AsyncObservable.Retry(source, retryCount); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"retryCount\") { /* use parameterless Retry for infinite retries */ }","preventionTips":["Use parameterless Retry(source) for 'retry forever', not -1.","Clamp computed attempt counters with Math.Max(0, n).","Validate maxRetries config at load time."],"tags":["argument-validation","argument-out-of-range","retry","reactive-extensions"],"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-15T23:17:13.987Z"}