TechnitiumSoftware/DnsServer · error · ArgumentOutOfRangeException
MaxStatFileDays must be greater than or equal to 0.
Error message
MaxStatFileDays must be greater than or equal to 0.
What it means
Thrown by StatsManager.MaxStatFileDays setter when the assigned value is negative. MaxStatFileDays controls how many days of .stat files are retained; 0 disables cleanup entirely (the cleanup timer is stopped via Timeout.Infinite). Negative values have no meaning and are rejected before field assignment.
Source
Thrown at DnsServerCore/Dns/StatsManager.cs:1704
{
_enableInMemoryStats = value;
if (_enableInMemoryStats)
{
_hourlyStatsCache.Clear();
_dailyStatsCache.Clear();
}
}
}
}
public int MaxStatFileDays
{
get { return _maxStatFileDays; }
set
{
if (value < 0)
throw new ArgumentOutOfRangeException(nameof(MaxStatFileDays), "MaxStatFileDays must be greater than or equal to 0.");
_maxStatFileDays = value;
if (_maxStatFileDays == 0)
_statsCleanupTimer.Change(Timeout.Infinite, Timeout.Infinite);
else
_statsCleanupTimer.Change(STATS_CLEANUP_TIMER_INITIAL_INTERVAL, STATS_CLEANUP_TIMER_PERIODIC_INTERVAL);
}
}
#endregion
class HourlyStats
{
#region variables
public readonly static HourlyStats Empty = new HourlyStats();
View on GitHub (pinned to d0484b6c1e)
Solutions
- Use 0 to disable cleanup, or any positive integer for the number of days to retain.
- Clamp the configured value to >= 0 in your UI/config layer before assigning.
- Treat any incoming -1/None sentinel as 0 (cleanup disabled) at the boundary.
Example fix
// before statsManager.MaxStatFileDays = configuredDays; // configuredDays == -1 // after statsManager.MaxStatFileDays = Math.Max(0, configuredDays);
Defensive patterns
Strategy: validation
Validate before calling
statsManager.MaxStatFileDays = Math.Max(0, configuredDays);
Try / catch
try { statsManager.MaxStatFileDays = configuredDays; }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == nameof(statsManager.MaxStatFileDays))
{ statsManager.MaxStatFileDays = 0; } Prevention
- Constrain the retention UI input to non-negative integers.
- Translate any -1/None config sentinel to 0 (cleanup disabled) at the boundary.
When it happens
Trigger: Assigning StatsManager.MaxStatFileDays to a value < 0, reachable from the stats settings UI or any config/API path that restores the retention setting.
Common situations: Operator types a negative number into the retention field; a config parser supplies -1 as a sentinel that is not translated to 0; an unvalidated integer field from a config file.
Related errors
- Network group map contains an invalid network address: {strN
- External to internal translation entries must have same addr
- External to internal translation entries must have same pref
- The SSO Authority URL length cannot be more than 255 chars.
- The SSO Authority URL scheme can be 'http' or 'https' only.
AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13).
Data as JSON: /api/errors/db196c71d80ad9c5.
Report an issue: GitHub.