TechnitiumSoftware/DnsServer · error · ArgumentOutOfRangeException

Port number valid range is from 0 to 65535.

Error message

Port number valid range is from 0 to 65535.

What it means

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).

Source

Thrown at DnsServerCore/Dns/DnsServer.cs:7705

                    ValidateQuicSupport();

                _enableDnsOverQuic = value;
            }
        }

        public bool EnableDnsOverHttpHelpRedirect
        {
            get { return _enableDnsOverHttpHelpRedirect; }
            set { _enableDnsOverHttpHelpRedirect = value; }
        }

        public int DnsOverUdpProxyPort
        {
            get { return _dnsOverUdpProxyPort; }
            set
            {
                if ((value < ushort.MinValue) || (value > ushort.MaxValue))
                    throw new ArgumentOutOfRangeException(nameof(DnsOverUdpProxyPort), "Port number valid range is from 0 to 65535.");

                _dnsOverUdpProxyPort = value;
            }
        }

        public int DnsOverTcpProxyPort
        {
            get { return _dnsOverTcpProxyPort; }
            set
            {
                if ((value < ushort.MinValue) || (value > ushort.MaxValue))
                    throw new ArgumentOutOfRangeException(nameof(DnsOverTcpProxyPort), "Port number valid range is from 0 to 65535.");

                _dnsOverTcpProxyPort = value;
            }
        }

        public int DnsOverHttpPort

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Use a port in 0..65535 (0 typically disables the UDP proxy; pick a real high port like 5353 if you need it active).
  2. Avoid reserved/privileged ports below 1024 unless you have explicit intent.
  3. Validate the int from config before assigning and fall back to a documented default.
  4. Send a corrected value via the settings API.

Example fix

// before
_dnsServer.DnsOverUdpProxyPort = 70000; // throws: > 65535

// after
_dnsServer.DnsOverUdpProxyPort = 5353;   // valid UDP proxy port
Defensive patterns

Strategy: validation

Validate before calling

static int ClampPort(int value) =>
    value < 0 ? 0 : value > 65535 ? 65535 : value;

_dnsServer.DnsOverUdpProxyPort = ClampPort(parsed);

Type guard

static bool IsValidPort(int value) => value >= 0 && value <= 65535;

Try / catch

try { _dnsServer.DnsOverUdpProxyPort = parsed; }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == nameof(DnsServer.DnsOverUdpProxyPort))
{ _dnsServer.DnsOverUdpProxyPort = 5353; }

Prevention

When it happens

Trigger: 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.

Common situations: Typing a port larger than 65535. Using a negative sentinel like -1 to mean 'disabled'. Copying a config whose proxy port field is corrupt.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/b246fe9073290741. Report an issue: GitHub.