{"record":{"id":"eb84d5fae06d4c32","repo":"TechnitiumSoftware/DnsServer","slug":"web-service-tls-certificate-path-cannot-be-null-or","errorCode":null,"errorMessage":"Web service TLS certificate path cannot be null or empty.","messagePattern":"Web service TLS certificate path cannot be null or empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/DnsWebService.cs","lineNumber":2746,"sourceCode":"            _webServiceCertificateLastModifiedOn = fileInfo.LastWriteTimeUtc;\n\n            _log.Write(\"Web Service TLS certificate was loaded: \" + tlsCertificatePath);\n        }\n\n        private void RemoveWebServiceTlsCertificate()\n        {\n            _webServiceSslServerAuthenticationOptions = null;\n\n            _webServiceTlsCertificatePath = null;\n            _webServiceTlsCertificatePassword = null;\n\n            StopTlsCertificateUpdateTimer();\n        }\n\n        public void SetWebServiceTlsCertificate(string webServiceTlsCertificatePath, string webServiceTlsCertificatePassword)\n        {\n            if (string.IsNullOrWhiteSpace(webServiceTlsCertificatePath))\n                throw new ArgumentException(\"Web service TLS certificate path cannot be null or empty.\", nameof(webServiceTlsCertificatePath));\n\n            if (webServiceTlsCertificatePath.Length > 255)\n                throw new ArgumentException(\"Web service TLS certificate path length cannot exceed 255 characters.\", nameof(webServiceTlsCertificatePath));\n\n            if (webServiceTlsCertificatePassword?.Length > 255)\n                throw new ArgumentException(\"Web service TLS certificate password length cannot exceed 255 characters.\", nameof(webServiceTlsCertificatePassword));\n\n            webServiceTlsCertificatePath = ConvertToAbsolutePath(webServiceTlsCertificatePath);\n\n            LoadWebServiceTlsCertificate(webServiceTlsCertificatePath, webServiceTlsCertificatePassword);\n\n            _webServiceTlsCertificatePath = ConvertToRelativePath(webServiceTlsCertificatePath);\n            _webServiceTlsCertificatePassword = webServiceTlsCertificatePassword;\n\n            StartTlsCertificateUpdateTimer();\n        }\n\n        private void CheckAndLoadSelfSignedCertificate(bool forceGenerateNew, bool throwException)","sourceCodeStart":2728,"sourceCodeEnd":2764,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/DnsWebService.cs#L2728-L2764","documentation":"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.","triggerScenarios":"Calling SetWebServiceTlsCertificate with null, \"\", or a whitespace-only string for webServiceTlsCertificatePath.","commonSituations":"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.","solutions":["Provide a non-empty path to a .pfx/.p12 certificate file.","Validate the path field is set before calling SetWebServiceTlsCertificate.","If TLS is not required, disable TLS instead of passing an empty path."],"exampleFix":"// before\n_dnsWebService.SetWebServiceTlsCertificate(path, password); // path may be null\n\n// after\nif (!string.IsNullOrWhiteSpace(path))\n    _dnsWebService.SetWebServiceTlsCertificate(path, password);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(webServiceTlsCertificatePath))\n    throw new ArgumentException(\"TLS certificate path is required.\");","typeGuard":"static bool HasTlsCertPath(string path) => !string.IsNullOrWhiteSpace(path);","tryCatchPattern":"null","preventionTips":["Validate required config fields before calling SetWebServiceTlsCertificate.","Default unset fields to a sentinel and refuse empty values.","Disable TLS explicitly rather than passing an empty path."],"tags":["dns-server","technitium","tls","certificate","input-validation","configuration","csharp"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}