{"record":{"id":"d41716a9310364e3","repo":"TechnitiumSoftware/DnsServer","slug":"zone-was-not-found-zonename-d41716","errorCode":null,"errorMessage":"Zone was not found: {zoneName}","messagePattern":"Zone was not found: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs","lineNumber":2471,"sourceCode":"                if (authZone is SubDomainZone subDomainZone)\n                {\n                    if (authZone.IsEmpty)\n                        _root.TryRemove(authZone.Name, out SubDomainZone _); //remove empty sub zone\n                    else\n                        subDomainZone.AutoUpdateState();\n                }\n            }\n        }\n\n        #endregion\n\n        #region zone transfer / import\n\n        public IReadOnlyList<DnsResourceRecord> QueryZoneTransferRecords(string zoneName)\n        {\n            AuthZoneInfo zoneInfo = GetAuthZoneInfo(zoneName);\n            if (zoneInfo is null)\n                throw new InvalidOperationException(\"Zone was not found: \" + zoneName);\n\n            //primary, secondary, and forwarder zones support zone transfer\n            IReadOnlyList<DnsResourceRecord> soaRecords = zoneInfo.ApexZone.GetRecords(DnsResourceRecordType.SOA);\n            if (soaRecords.Count != 1)\n                throw new InvalidOperationException(\"Zone must be a primary, secondary, or forwarder zone.\");\n\n            DnsResourceRecord soaRecord = soaRecords[0];\n\n            List<DnsResourceRecord> records = new List<DnsResourceRecord>();\n            ListAllZoneRecords(zoneName, records);\n\n            List<DnsResourceRecord> xfrRecords = new List<DnsResourceRecord>(records.Count + 1);\n\n            //start message\n            xfrRecords.Add(soaRecord);\n\n            foreach (DnsResourceRecord record in records)\n            {","sourceCodeStart":2453,"sourceCodeEnd":2489,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs#L2453-L2489","documentation":"Thrown by QueryZoneTransferRecords when GetAuthZoneInfo(zoneName) returns null, meaning no zone with that name exists in the zone tree. This is an InvalidOperationException (not DnsServerException) because it indicates a programming or protocol-level error rather than a user-facing DNS operation error. Zone transfer queries require an existing zone.","triggerScenarios":"Calling QueryZoneTransferRecords(zoneName) where zoneName does not match any registered zone. This method is the AXFR data source; a secondary server requesting transfer for an unknown zone, or internal code passing a wrong name, triggers it.","commonSituations":"Secondary server configured to transfer a zone that the primary does not host; zone name typo in transfer configuration; zone was deleted but transfer schedule still runs; root zone edge case where zoneName is empty string and no root zone exists.","solutions":["Verify the zone exists by calling GetAuthZoneInfo before requesting a zone transfer.","Check the zone name spelling and format in the transfer configuration.","Ensure the zone was loaded successfully at server startup.","For secondary servers, validate the primary zone name matches exactly."],"exampleFix":"// before\nvar xfrRecords = authZoneManager.QueryZoneTransferRecords(zoneName);\n\n// after\nAuthZoneInfo info = authZoneManager.GetAuthZoneInfo(zoneName);\nif (info is null)\n    throw new InvalidOperationException($\"Cannot transfer: zone '{zoneName}' does not exist.\");\nvar xfrRecords = authZoneManager.QueryZoneTransferRecords(zoneName);","handlingStrategy":"validation","validationCode":"AuthZoneInfo info = authZoneManager.GetAuthZoneInfo(zoneName);\nif (info is null)\n    throw new InvalidOperationException($\"Cannot transfer: zone '{zoneName}' does not exist.\");","typeGuard":"static bool ZoneExists(AuthZoneManager mgr, string zoneName)\n    => mgr.GetAuthZoneInfo(zoneName) is not null;","tryCatchPattern":"try\n{\n    var records = authZoneManager.QueryZoneTransferRecords(zoneName);\n}\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Zone was not found\"))\n{\n    logger.LogError(\"AXFR failed: zone '{Zone}' does not exist.\", zoneName);\n}","preventionTips":["Verify zone existence with GetAuthZoneInfo before requesting zone transfer.","Cross-check zone names between primary and secondary configurations.","Handle null zone info gracefully in transfer scheduling code."],"tags":["zone-transfer","axfr","zone-management","validation"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}