TechnitiumSoftware/DnsServer · error · ArgumentException

Web service TLS certificate path cannot be null or empty.

Error message

Web service TLS certificate path cannot be null or empty.

What it means

ArgumentException thrown by SetWebServiceTlsCertificate when the supplied certificate path is null, empty, or whitespace. The path is mandatory before any length/format checks or absolute-path conversion.

Source

Thrown at DnsServerCore/DnsWebService.cs:2746

            _webServiceCertificateLastModifiedOn = fileInfo.LastWriteTimeUtc;

            _log.Write("Web Service TLS certificate was loaded: " + tlsCertificatePath);
        }

        private void RemoveWebServiceTlsCertificate()
        {
            _webServiceSslServerAuthenticationOptions = null;

            _webServiceTlsCertificatePath = null;
            _webServiceTlsCertificatePassword = null;

            StopTlsCertificateUpdateTimer();
        }

        public void SetWebServiceTlsCertificate(string webServiceTlsCertificatePath, string webServiceTlsCertificatePassword)
        {
            if (string.IsNullOrWhiteSpace(webServiceTlsCertificatePath))
                throw new ArgumentException("Web service TLS certificate path cannot be null or empty.", nameof(webServiceTlsCertificatePath));

            if (webServiceTlsCertificatePath.Length > 255)
                throw new ArgumentException("Web service TLS certificate path length cannot exceed 255 characters.", nameof(webServiceTlsCertificatePath));

            if (webServiceTlsCertificatePassword?.Length > 255)
                throw new ArgumentException("Web service TLS certificate password length cannot exceed 255 characters.", nameof(webServiceTlsCertificatePassword));

            webServiceTlsCertificatePath = ConvertToAbsolutePath(webServiceTlsCertificatePath);

            LoadWebServiceTlsCertificate(webServiceTlsCertificatePath, webServiceTlsCertificatePassword);

            _webServiceTlsCertificatePath = ConvertToRelativePath(webServiceTlsCertificatePath);
            _webServiceTlsCertificatePassword = webServiceTlsCertificatePassword;

            StartTlsCertificateUpdateTimer();
        }

        private void CheckAndLoadSelfSignedCertificate(bool forceGenerateNew, bool throwException)

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Provide a non-empty path to a .pfx/.p12 certificate file.
  2. Validate the path field is set before calling SetWebServiceTlsCertificate.
  3. If TLS is not required, disable TLS instead of passing an empty path.

Example fix

// before
_dnsWebService.SetWebServiceTlsCertificate(path, password); // path may be null

// after
if (!string.IsNullOrWhiteSpace(path))
    _dnsWebService.SetWebServiceTlsCertificate(path, password);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(webServiceTlsCertificatePath))
    throw new ArgumentException("TLS certificate path is required.");

Type guard

static bool HasTlsCertPath(string path) => !string.IsNullOrWhiteSpace(path);

Try / catch

null

Prevention

When it happens

Trigger: Calling SetWebServiceTlsCertificate with null, "", or a whitespace-only string for webServiceTlsCertificatePath.

Common situations: Config UI/API call with a missing field; script passing an unset environment variable; JSON config with an empty/omitted path; programmatic caller defaulting to null.

Understand the failure class

Related errors


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