{"record":{"id":"c1c7e040a19b1c43","repo":"App-vNext/Polly","slug":"numberofexecutions-per-timespan-must-be-an-integer-c1c7e0","errorCode":null,"errorMessage":"numberOfExecutions per timespan must be an integer greater than or equal to 1.","messagePattern":"numberOfExecutions per timespan must be an integer greater than or equal to 1\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Polly/RateLimit/RateLimitTResultSyntax.cs","lineNumber":68,"sourceCode":"    /// with a maximum burst size of <paramref name=\"maxBurst\"/>.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of return values this policy will handle.</typeparam>\n    /// <param name=\"numberOfExecutions\">The number of executions (call it N) permitted per timespan.</param>\n    /// <param name=\"perTimeSpan\">How often N executions are permitted.</param>\n    /// <param name=\"maxBurst\">The maximum number of executions that will be permitted in a single burst (for example if none have been executed for a while).\n    /// This equates to the bucket-capacity of a token-bucket implementation.</param>\n    /// <param name=\"retryAfterFactory\">An (optional) factory to use to express retry-after back to the caller, when an operation is rate-limited.\n    /// <remarks>If null, a <see cref=\"RateLimitRejectedException\"/> with property <see cref=\"RateLimitRejectedException.RetryAfter\"/> will be thrown to indicate rate-limiting.</remarks></param>\n    /// <returns>The policy instance.</returns>\n    public static RateLimitPolicy<TResult> RateLimit<TResult>(\n        int numberOfExecutions,\n        TimeSpan perTimeSpan,\n        int maxBurst,\n        Func<TimeSpan, Context, TResult>? retryAfterFactory)\n    {\n        if (numberOfExecutions < 1)\n        {\n            throw new ArgumentOutOfRangeException(nameof(numberOfExecutions), numberOfExecutions, $\"{nameof(numberOfExecutions)} per timespan must be an integer greater than or equal to 1.\");\n        }\n\n        if (perTimeSpan <= TimeSpan.Zero)\n        {\n            throw new ArgumentOutOfRangeException(nameof(perTimeSpan), perTimeSpan, $\"{nameof(perTimeSpan)} must be a positive timespan.\");\n        }\n\n        if (maxBurst < 1)\n        {\n            throw new ArgumentOutOfRangeException(nameof(maxBurst), maxBurst, $\"{nameof(maxBurst)} must be an integer greater than or equal to 1.\");\n        }\n\n        var onePer = TimeSpan.FromTicks(perTimeSpan.Ticks / numberOfExecutions);\n\n        if (onePer <= TimeSpan.Zero)\n        {\n            throw new ArgumentOutOfRangeException(nameof(perTimeSpan), perTimeSpan, \"The number of executions per timespan must be positive.\");\n        }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/RateLimit/RateLimitTResultSyntax.cs#L50-L86","documentation":"Thrown by RateLimitTResultSyntax.RateLimit<TResult> when numberOfExecutions is less than 1. This is the generic (TResult-returning) counterpart of the non-generic guard; a zero-execution limit would reject every call.","triggerScenarios":"Calling Policy.RateLimit<TResult>(numberOfExecutions: 0, ...) or a negative value on the generic sync overload that also takes a retryAfterFactory.","commonSituations":"Per-result-type rate limit built from config defaulting to 0; computed value that floors to zero.","solutions":["Set numberOfExecutions to at least 1.","Validate the source config value before building the policy.","Skip policy creation when the configured limit is not positive."],"exampleFix":"// before\nvar policy = Policy.RateLimit<MyResult>(0, TimeSpan.FromSeconds(10), 5, factory);\n// after\nvar policy = Policy.RateLimit<MyResult>(5, TimeSpan.FromSeconds(10), 5, factory);","handlingStrategy":"validation","validationCode":"const int DefaultExecutions = 5;\nvar numberOfExecutions = Math.Max(1, config.GetValue(\"RateLimit:Executions\", DefaultExecutions));\nvar policy = Policy.RateLimit<TResult>(numberOfExecutions, perTimeSpan, maxBurst, retryAfterFactory);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate numeric config with Math.Max(1, value) at startup.","Provide non-zero defaults for execution counts.","Log config fallbacks so missing keys are detectable."],"tags":["rate-limit","argumentoutofrange","generic","configuration"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}