{"record":{"id":"7d4d4edeba723ab0","repo":"TechnitiumSoftware/DnsServer","slug":"zone-already-exists-zoneinfo-displayname","errorCode":null,"errorMessage":"Zone already exists: <zoneInfo.DisplayName>","messagePattern":"Zone already exists: <zoneInfo\\.DisplayName>","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs","lineNumber":745,"sourceCode":"                    apexZone = new CatalogZone(_dnsServer, zoneInfo);\n                    break;\n\n                case AuthZoneType.SecondaryCatalog:\n                    SecondaryCatalogZone secondaryCatalogZone = new SecondaryCatalogZone(_dnsServer, zoneInfo);\n                    secondaryCatalogZone.ZoneAdded += SecondaryCatalogZoneAdded;\n                    secondaryCatalogZone.ZoneRemoved += SecondaryCatalogZoneRemoved;\n\n                    apexZone = secondaryCatalogZone;\n                    break;\n\n                default:\n                    throw new InvalidDataException(\"DNS zone type not supported.\");\n            }\n\n            if (_root.TryAdd(apexZone))\n                return apexZone;\n\n            throw new DnsServerException(\"Zone already exists: \" + zoneInfo.DisplayName);\n        }\n\n        internal AuthZone GetOrAddSubDomainZone(string zoneName, string domain)\n        {\n            return _root.GetOrAddSubDomainZone(zoneName, domain, delegate ()\n            {\n                if (!_root.TryGet(zoneName, out ApexZone apexZone))\n                    throw new DnsServerException(\"Zone was not found for domain: \" + domain);\n\n                if (apexZone is PrimaryZone primaryZone)\n                    return new PrimarySubDomainZone(primaryZone, domain);\n                else if (apexZone is SecondaryCatalogZone secondaryCatalogZone)\n                    return new SecondaryCatalogSubDomainZone(secondaryCatalogZone, domain);\n                else if (apexZone is SecondaryZone secondaryZone)\n                    return new SecondarySubDomainZone(secondaryZone, domain);\n                else if (apexZone is CatalogZone catalogZone)\n                    return new CatalogSubDomainZone(catalogZone, domain);\n                else if (apexZone is ForwarderZone forwarderZone)","sourceCodeStart":727,"sourceCodeEnd":763,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs#L727-L763","documentation":"Thrown by AuthZoneManager.CreateEmptyApexZone when _root.TryAdd(apexZone) returns false, meaning an apex zone with the same name already exists in the tree. The manager refuses to silently overwrite an existing zone and surfaces the conflict, including the zone's display name.","triggerScenarios":"Calling CreateEmptyApexZone (directly or via AddZone) for a zone name that is already present in the authoritative zone tree — TryAdd fails because the key is taken.","commonSituations":"Re-adding a zone without deleting it first, a race where two callers add the same zone, importing a zone list with duplicates, or a UI/API retry that double-submits.","solutions":["Check for an existing zone (GetAuthZoneInfo/TryGet) before adding, or delete the existing zone first.","Make add operations idempotent at the caller: if it exists, update rather than re-add.","Guard concurrent adds with a lock or check-then-add under the same synchronization."],"exampleFix":"// before\nzoneManager.AddZone(name, type, ...); // throws if exists\n\n// after\nif (zoneManager.GetAuthZoneInfo(name, true) is null)\n    zoneManager.AddZone(name, type, ...);\nelse\n    zoneManager.UpdateZone(name, ...);","handlingStrategy":"validation","validationCode":"bool ZoneExists(AuthZoneManager mgr, string name) =>\n    mgr.GetAuthZoneInfo(name, true) is not null;\n// usage:\nif (!ZoneExists(mgr, name))\n    mgr.AddZone(name, type, ...);","typeGuard":null,"tryCatchPattern":"try { zoneManager.AddZone(name, type, ...); }\ncatch (DnsServerException ex) when (ex.Message.StartsWith(\"Zone already exists\"))\n{\n    // idempotent: update the existing zone instead\n    zoneManager.UpdateZone(name, ...);\n}","preventionTips":["Check for an existing zone before adding.","Make add operations idempotent (update if exists).","Serialize concurrent add requests to avoid races."],"tags":["dns","csharp","zone-management","duplicate","concurrency","technitium"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}