{"record":{"id":"b246fe9073290741","repo":"TechnitiumSoftware/DnsServer","slug":"port-number-valid-range-is-from-0-to-65535","errorCode":null,"errorMessage":"Port number valid range is from 0 to 65535.","messagePattern":"Port number valid range is from 0 to 65535\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/DnsServer.cs","lineNumber":7705,"sourceCode":"                    ValidateQuicSupport();\n\n                _enableDnsOverQuic = value;\n            }\n        }\n\n        public bool EnableDnsOverHttpHelpRedirect\n        {\n            get { return _enableDnsOverHttpHelpRedirect; }\n            set { _enableDnsOverHttpHelpRedirect = value; }\n        }\n\n        public int DnsOverUdpProxyPort\n        {\n            get { return _dnsOverUdpProxyPort; }\n            set\n            {\n                if ((value < ushort.MinValue) || (value > ushort.MaxValue))\n                    throw new ArgumentOutOfRangeException(nameof(DnsOverUdpProxyPort), \"Port number valid range is from 0 to 65535.\");\n\n                _dnsOverUdpProxyPort = value;\n            }\n        }\n\n        public int DnsOverTcpProxyPort\n        {\n            get { return _dnsOverTcpProxyPort; }\n            set\n            {\n                if ((value < ushort.MinValue) || (value > ushort.MaxValue))\n                    throw new ArgumentOutOfRangeException(nameof(DnsOverTcpProxyPort), \"Port number valid range is from 0 to 65535.\");\n\n                _dnsOverTcpProxyPort = value;\n            }\n        }\n\n        public int DnsOverHttpPort","sourceCodeStart":7687,"sourceCodeEnd":7723,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/DnsServer.cs#L7687-L7723","documentation":"Thrown by the DnsOverUdpProxyPort setter. This int holds the UDP port for the DNS reverse-proxy service. Because it is compared against ushort.MinValue (0) and ushort.MaxValue (65535), any value outside [0, 65535] throws ArgumentOutOfRangeException. Note 0 is allowed here (it does not have the port-53 exclusion that the DoH/DoT/DoQ ports enforce).","triggerScenarios":"Assigning DnsServer.DnsOverUdpProxyPort a value < 0 or > 65535 (e.g. -1, 70000). Reached via the settings API reverse-proxy UDP port field or binary config deserialization.","commonSituations":"Typing a port larger than 65535. Using a negative sentinel like -1 to mean 'disabled'. Copying a config whose proxy port field is corrupt.","solutions":["Use a port in 0..65535 (0 typically disables the UDP proxy; pick a real high port like 5353 if you need it active).","Avoid reserved/privileged ports below 1024 unless you have explicit intent.","Validate the int from config before assigning and fall back to a documented default.","Send a corrected value via the settings API."],"exampleFix":"// before\n_dnsServer.DnsOverUdpProxyPort = 70000; // throws: > 65535\n\n// after\n_dnsServer.DnsOverUdpProxyPort = 5353;   // valid UDP proxy port","handlingStrategy":"validation","validationCode":"static int ClampPort(int value) =>\n    value < 0 ? 0 : value > 65535 ? 65535 : value;\n\n_dnsServer.DnsOverUdpProxyPort = ClampPort(parsed);","typeGuard":"static bool IsValidPort(int value) => value >= 0 && value <= 65535;","tryCatchPattern":"try { _dnsServer.DnsOverUdpProxyPort = parsed; }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == nameof(DnsServer.DnsOverUdpProxyPort))\n{ _dnsServer.DnsOverUdpProxyPort = 5353; }","preventionTips":["Never use negative sentinels; use 0 to disable.","Validate port ints to [0, 65535] before assignment.","Confirm the port is free before binding."],"tags":["dns","network","port","proxy","configuration","argumentoutofrange"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}