{"record":{"id":"9eb4f1a76823dd41","repo":"HangfireIO/Hangfire","slug":"workercount-property-value-should-be-positive","errorCode":null,"errorMessage":"WorkerCount property value should be positive.","messagePattern":"WorkerCount property value should be positive\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/BackgroundJobServerOptions.cs","lineNumber":72,"sourceCode":"            TimeZoneResolver = null;\n            TaskScheduler = TaskScheduler.Default;\n        }\n        \n        public string ServerName { get; set; }\n\n        /// <summary>\n        /// Gets or sets whether storage instance will include only <see cref=\"Worker\"/> and required\n        /// <see cref=\"ServerWatchdog\"/> and <see cref=\"ServerJobCancellationWatcher\"/> processes. No\n        /// storage-related processes or recurring/delayed job schedulers will be included.\n        /// </summary>\n        public bool IsLightweightServer { get; set; }\n\n        public int WorkerCount\n        {\n            get { return _workerCount; }\n            set\n            {\n                if (value <= 0) throw new ArgumentOutOfRangeException(nameof(value), \"WorkerCount property value should be positive.\");\n\n                _workerCount = value;\n            }\n        }\n\n        public string[] Queues\n        {\n            get { return _queues; }\n            set\n            {\n                if (value == null) throw new ArgumentNullException(nameof(value));\n                if (value.Length == 0) throw new ArgumentException(\"You should specify at least one queue to listen.\", nameof(value));\n\n                _queues = value;\n            }\n        }\n\n        public TimeSpan StopTimeout","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/BackgroundJobServerOptions.cs#L54-L90","documentation":"This ArgumentOutOfRangeException(\"value\", \"WorkerCount property value should be positive.\") is thrown by the WorkerCount setter of BackgroundJobServerOptions when the value is less than or equal to zero. WorkerCount controls how many Worker instances process jobs; a non-positive count would create no workers, so Hangfire rejects it at assignment time. The default is min(Environment.ProcessorCount * 5, 20).","triggerScenarios":"Assigning options.WorkerCount = 0 or a negative number, e.g. from a misbound configuration value, a division that rounds to zero, or Environment.ProcessorCount-derived math that produced zero.","commonSituations":"Binding WorkerCount from a config section that is missing/empty (parsed as 0); computing WorkerCount from a percentage or CPU metric that returned 0; deployment where a scaling setting was set to 0 to disable workers instead of using a different mechanism; test fixtures that default numeric fields to 0.","solutions":["Set WorkerCount to a positive integer (1 is the minimum valid value).","Coerce bound config: options.WorkerCount = Math.Max(1, parsedValue).","Leave WorkerCount unset to use the default (min(ProcessorCount*5, 20)).","Validate the config value at startup before assigning it to the options."],"exampleFix":"// before\noptions.WorkerCount = int.Parse(config[\"Workers\"]); // empty -> 0\n\n// after\noptions.WorkerCount = Math.Max(1, int.Parse(config[\"Workers\"]));","handlingStrategy":"validation","validationCode":"int parsed = int.TryParse(config[\"Workers\"], out var w) ? w : new BackgroundJobServerOptions().WorkerCount;\noptions.WorkerCount = Math.Max(1, parsed);","typeGuard":"static bool IsValidWorkerCount(int value) => value > 0;","tryCatchPattern":"try { options.WorkerCount = value; }\ncatch (ArgumentOutOfRangeException) { options.WorkerCount = new BackgroundJobServerOptions().WorkerCount; }","preventionTips":["Clamp bound config with Math.Max(1, value).","Validate config at startup.","Leave unset to use the default."],"tags":["csharp","hangfire","argumentoutofrangeexception","configuration","validation","background-jobs"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}