{"record":{"id":"2d0346fab72a47c2","repo":"TechnitiumSoftware/DnsServer","slug":"lease-time-in-hours-must-be-between-0-to-23","errorCode":null,"errorMessage":"Lease time in hours must be between 0 to 23.","messagePattern":"Lease time in hours must be between 0 to 23\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/Scope.cs","lineNumber":1898,"sourceCode":"        public ushort LeaseTimeDays\n        {\n            get { return _leaseTimeDays; }\n            set\n            {\n                if (value > 999)\n                    throw new ArgumentOutOfRangeException(nameof(LeaseTimeDays), \"Lease time in days must be between 0 to 999.\");\n\n                _leaseTimeDays = value;\n            }\n        }\n\n        public byte LeaseTimeHours\n        {\n            get { return _leaseTimeHours; }\n            set\n            {\n                if (value > 23)\n                    throw new ArgumentOutOfRangeException(nameof(LeaseTimeHours), \"Lease time in hours must be between 0 to 23.\");\n\n                _leaseTimeHours = value;\n            }\n        }\n\n        public byte LeaseTimeMinutes\n        {\n            get { return _leaseTimeMinutes; }\n            set\n            {\n                if (value > 59)\n                    throw new ArgumentOutOfRangeException(nameof(LeaseTimeMinutes), \"Lease time in minutes must be between 0 to 59.\");\n\n                _leaseTimeMinutes = value;\n            }\n        }\n\n        public ushort OfferDelayTime","sourceCodeStart":1880,"sourceCodeEnd":1916,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/Scope.cs#L1880-L1916","documentation":"Thrown by the LeaseTimeHours setter (byte) when the value exceeds 23. Hours are a sub-day component of the lease time and must stay within a 24-hour day (0..23).","triggerScenarios":"Assigning scope.LeaseTimeHours = value where value > 23. Happens when a whole-hour count is split into days/hours incorrectly, or a config feeds a raw hour total into the hours field.","commonSituations":"Decomposing total hours without dividing by 24, UI not bounding the hours spinner, or deserializing a minutes/hours mix-up.","solutions":["Clamp to 0..23 before assignment.","When converting a total-hour figure, set LeaseTimeDays = total / 24 and LeaseTimeHours = total % 24.","Validate config so hours never exceeds 23.","Confirm the field is hours, not minutes."],"exampleFix":"// before\nscope.LeaseTimeHours = (byte)totalHours; // throws if > 23\n\n// after\nscope.LeaseTimeDays  = (ushort)(totalHours / 24);\nscope.LeaseTimeHours = (byte)(totalHours % 24);","handlingStrategy":"validation","validationCode":"if (hours > 23) throw new ConfigurationException(\"LeaseTimeHours must be <= 23\");\nscope.LeaseTimeHours = (byte)Math.Clamp(hours, 0, 23);","typeGuard":"static bool IsValidLeaseTimeHours(int hours) => hours >= 0 && hours <= 23;","tryCatchPattern":"try { scope.LeaseTimeHours = value; }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"LeaseTimeHours\")\n{ /* clamp and retry */ }","preventionTips":["Decompose a total-hour figure into days (n/24) and hours (n%24).","Bound the hours spinner to 0..23.","Confirm units: hours, not minutes."],"tags":["dhcp","validation","scope","lease-time","argument"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}