{"record":{"id":"ffe130ed4d3fcb71","repo":"TechnitiumSoftware/DnsServer","slug":"cannot-set-records-in-zone","errorCode":null,"errorMessage":"Cannot set records in {} zone.","messagePattern":"Cannot set records in (.+?) zone\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/Zones/SecondarySubDomainZone.cs","lineNumber":48,"sourceCode":"        readonly SecondaryZone _secondaryZone;\n\n        #endregion\n\n        #region constructor\n\n        public SecondarySubDomainZone(SecondaryZone secondaryZone, string name)\n            : base(secondaryZone, name)\n        {\n            _secondaryZone = secondaryZone;\n        }\n\n        #endregion\n\n        #region public\n\n        public override void SetRecords(DnsResourceRecordType type, IReadOnlyList<DnsResourceRecord> records)\n        {\n            throw new InvalidOperationException(\"Cannot set records in \" + _secondaryZone.GetZoneTypeName() + \" zone.\");\n        }\n\n        public override bool AddRecord(DnsResourceRecord record)\n        {\n            throw new InvalidOperationException(\"Cannot add record in \" + _secondaryZone.GetZoneTypeName() + \" zone.\");\n        }\n\n        public override bool DeleteRecord(DnsResourceRecordType type, DnsResourceRecordData record)\n        {\n            throw new InvalidOperationException(\"Cannot delete record in \" + _secondaryZone.GetZoneTypeName() + \" zone.\");\n        }\n\n        public override bool DeleteRecords(DnsResourceRecordType type)\n        {\n            throw new InvalidOperationException(\"Cannot delete records in \" + _secondaryZone.GetZoneTypeName() + \" zone.\");\n        }\n\n        public override void UpdateRecord(DnsResourceRecord oldRecord, DnsResourceRecord newRecord)","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/Zones/SecondarySubDomainZone.cs#L30-L66","documentation":"Thrown unconditionally by SecondarySubDomainZone.SetRecords. A secondary sub-domain zone is read-only (its contents come from zone transfers of the parent secondary zone), so any attempt to author records locally is rejected with InvalidOperationException. The message embeds the parent zone's type name via _secondaryZone.GetZoneTypeName().","triggerScenarios":"Calling subZone.SetRecords(type, records) on a SecondarySubDomainZone instance.","commonSituations":"Generic zone-management code that calls SetRecords on every zone including sub-domains; migrating a primary sub-domain to secondary without updating write paths.","solutions":["Detect the zone is a SecondarySubDomainZone (read-only) and skip SetRecords.","If authoring is required, convert the zone to a primary sub-domain zone.","Centralize record writes behind a guard that checks the zone type."],"exampleFix":"// before\nzone.SetRecords(type, records);\n\n// after\nif (zone is SecondarySubDomainZone)\n    throw new InvalidOperationException(\"zone is read-only; use a primary zone to author records.\");\nzone.SetRecords(type, records);","handlingStrategy":"type-guard","validationCode":"if (zone is SecondarySubDomainZone)\n    throw new InvalidOperationException(\"Zone is read-only.\");\nzone.SetRecords(type, records);","typeGuard":"static bool IsWritable(AuthZone zone) => zone is not SecondarySubDomainZone;","tryCatchPattern":"null","preventionTips":["Route all writes through a writability guard keyed on zone type.","Document which zone types are read-only in your zone factory."],"tags":["dns","secondary-subdomain-zone","read-only","immutable","zone-type"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}