{"record":{"id":"e21d15075867d39a","repo":"App-vNext/Polly","slug":"numberofexecutions-per-timespan-must-be-an-integer-e21d15","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/RateLimitSyntax.cs","lineNumber":32,"sourceCode":"        TimeSpan perTimeSpan) =>\n        RateLimit(numberOfExecutions, perTimeSpan, 1);\n\n    /// <summary>\n    /// Builds a RateLimit <see cref=\"Policy\"/> that will rate-limit executions to <paramref name=\"numberOfExecutions\"/> per the timespan given.\n    /// </summary>\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    /// <returns>The policy instance.</returns>\n    public static RateLimitPolicy RateLimit(\n        int numberOfExecutions,\n        TimeSpan perTimeSpan,\n        int maxBurst)\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":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/RateLimit/RateLimitSyntax.cs#L14-L50","documentation":"Thrown by RateLimitSyntax.RateLimit when numberOfExecutions is less than 1. A rate limiter permitting zero executions per window would reject every call and serve no purpose, so the builder rejects it up front.","triggerScenarios":"Calling Policy.RateLimit(numberOfExecutions: 0, ...) or any negative value via the sync non-generic RateLimit extension.","commonSituations":"Configuring rate limits from appsettings where a missing key defaults to 0; passing a computed/scaled value that rounds down to zero.","solutions":["Set numberOfExecutions to at least 1.","Validate the config value with a fallback/default when loading from settings.","Guard the caller: if (rateLimit <= 0) skip building the policy."],"exampleFix":"// before\nvar policy = Policy.RateLimit(0, TimeSpan.FromSeconds(10), 5);\n// after\nvar policy = Policy.RateLimit(5, TimeSpan.FromSeconds(10), 5);","handlingStrategy":"validation","validationCode":"const int DefaultExecutions = 5;\nvar numberOfExecutions = Math.Max(1, config.GetValue(\"RateLimit:Executions\", DefaultExecutions));\nvar policy = Policy.RateLimit(numberOfExecutions, perTimeSpan, maxBurst);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate numeric rate-limit config with Math.Max(1, value) at startup.","Provide non-zero defaults in appsettings.json.","Log a warning when config falls back to a default so misconfiguration is visible."],"tags":["rate-limit","argumentoutofrange","configuration","validation"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}