{"record":{"id":"a3a188b8f15c9f3f","repo":"HangfireIO/Hangfire","slug":"the-value-must-be-a-positive-number","errorCode":null,"errorMessage":"The value must be a positive number","messagePattern":"The value must be a positive number","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.SqlServer/SqlServerConnection.cs","lineNumber":407,"sourceCode":"\n                var result = connection.Query<string>(\n                    query,\n                    new { key = key },\n                    commandTimeout: storage.CommandTimeout);\n\n                return new HashSet<string>(result);\n            }, key);\n        }\n\n        public override string GetFirstByLowestScoreFromSet(string key, double fromScore, double toScore)\n        {\n            return GetFirstByLowestScoreFromSet(key, fromScore, toScore, 1).FirstOrDefault();\n        }\n\n        public override List<string> GetFirstByLowestScoreFromSet(string key, double fromScore, double toScore, int count)\n        {\n            if (key == null) throw new ArgumentNullException(nameof(key));\n            if (count <= 0) throw new ArgumentException(\"The value must be a positive number\", nameof(count));\n            if (toScore < fromScore) throw new ArgumentException(\"The `toScore` value must be higher or equal to the `fromScore` value.\", nameof(toScore));\n\n            return _storage.UseConnection(_dedicatedConnection, static (storage, connection, pair) =>\n            {\n                var query = storage.GetQueryFromTemplate(static schemaName =>\n$@\"select top (@count) Value from [{schemaName}].[Set] with (forceseek) where [Key] = @key and Score between @from and @to order by Score\");\n\n                var result = connection.Query<string>(\n                    query,\n                    new { count = pair.Value.Item3, key = pair.Key, from = pair.Value.Item1, to = pair.Value.Item2 },\n                    commandTimeout: storage.CommandTimeout);\n\n                return result.ToList();\n            }, new KeyValuePair<string, ValueTriple<double, double, int>>(key, CreateTriple(fromScore, toScore, count)));\n        }\n\n        public override void SetRangeInHash(string key, IEnumerable<KeyValuePair<string, string>> keyValuePairs)\n        {","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.SqlServer/SqlServerConnection.cs#L389-L425","documentation":"ArgumentException thrown by SqlServerConnection.GetFirstByLowestScoreFromSet(string,double,double,int) when the requested count is less than or equal to zero. The method maps directly to a 'select top (@count)' query, which requires a strictly positive integer.","triggerScenarios":"Calling GetFirstByLowestScoreFromSet with a count argument of 0 or a negative number (often via a derived/monitoring caller that computes count from a configuration value or pagination).","commonSituations":"A 'take' / 'pageSize' variable defaulting to 0; computing count as a difference that evaluated to 0 or negative; misconfigured limit passed from the dashboard or an API.","solutions":["Validate that count is >= 1 before calling, and default to a sensible positive value (e.g. 1) when unset.","Guard pagination inputs at the boundary: if (count < 1) count = 1;."],"exampleFix":"// before\nvar items = connection.GetFirstByLowestScoreFromSet(key, from, to, requestedCount); // requestedCount could be 0\n\n// after\nvar items = connection.GetFirstByLowestScoreFromSet(key, from, to, Math.Max(1, requestedCount));","handlingStrategy":"validation","validationCode":"static List<string> SafeGetFirstByLowestScore(IStorageConnection conn, string key, double from, double to, int count)\n{\n    if (count < 1) count = 1;\n    return conn.GetFirstByLowestScoreFromSet(key, from, to, count);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default pagination 'take' values to a positive constant.","Guard user-supplied limit inputs at the API boundary.","Unit-test callers with count = 0 and negative values."],"tags":["sqlserver","argument","set"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}