{"record":{"id":"f1cd64cc7b956bfe","repo":"TechnitiumSoftware/DnsServer","slug":"cannot-add-record-use-setrecords-for-type-rec-f1cd64","errorCode":null,"errorMessage":"Cannot add record: use SetRecords() for {type} record","messagePattern":"Cannot add record: use SetRecords\\(\\) for (.+?) record","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/Zones/PrimaryZone.cs","lineNumber":2641,"sourceCode":"            {\n                switch (record.Type)\n                {\n                    case DnsResourceRecordType.ANAME:\n                    case DnsResourceRecordType.APP:\n                        throw new DnsServerException(\"The record type is not supported by DNSSEC signed primary zones.\");\n\n                    default:\n                        if (record.GetAuthGenericRecordInfo().Disabled)\n                            throw new DnsServerException(\"Cannot add record: disabling records in a signed zones is not supported.\");\n\n                        break;\n                }\n            }\n\n            switch (record.Type)\n            {\n                case DnsResourceRecordType.APP:\n                    throw new InvalidOperationException(\"Cannot add record: use SetRecords() for \" + record.Type.ToString() + \" record\");\n\n                case DnsResourceRecordType.DS:\n                    throw new InvalidOperationException(\"Cannot set DS record at zone apex.\");\n\n                case DnsResourceRecordType.DNSKEY:\n                case DnsResourceRecordType.RRSIG:\n                case DnsResourceRecordType.NSEC:\n                case DnsResourceRecordType.NSEC3PARAM:\n                case DnsResourceRecordType.NSEC3:\n                    throw new InvalidOperationException(\"Cannot add DNSSEC record.\");\n\n                case DnsResourceRecordType.FWD:\n                    throw new DnsServerException(\"The record type is not supported by primary zones.\");\n\n                default:\n                    if (record.OriginalTtlValue > GetZoneSoaExpire())\n                        throw new DnsServerException(\"Cannot add record: TTL cannot be greater than SOA EXPIRE.\");\n","sourceCodeStart":2623,"sourceCodeEnd":2659,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/Zones/PrimaryZone.cs#L2623-L2659","documentation":"Thrown as InvalidOperationException by PrimaryZone.AddRecord() when the record type is APP. APP records are managed as a complete set, not appended individually, so AddRecord refuses them and points the caller to SetRecords(). This is a programming/usage error.","triggerScenarios":"Calling AddRecord with a record whose Type is DnsResourceRecordType.APP on a primary zone.","commonSituations":"Generic record-adding loops that call AddRecord for every record type; attempting to append a single APP record instead of replacing the APP set.","solutions":["Use SetRecords(DnsResourceRecordType.APP, ...) instead of AddRecord to manage APP records as a set.","Exclude APP from any AddRecord loop.","Check the record type and route APP to SetRecords."],"exampleFix":"// before\nzone.AddRecord(appRecord); // throws: APP needs SetRecords\n\n// after\nzone.SetRecords(DnsResourceRecordType.APP, new[] { appRecord });","handlingStrategy":"type-guard","validationCode":"if (record.Type == DnsResourceRecordType.APP)\n    throw new ArgumentException(\"Use SetRecords() for APP records.\");\n\nzone.AddRecord(record);","typeGuard":"static bool IsIndividuallyAddable(DnsResourceRecordType t) =>\n    t != DnsResourceRecordType.APP;","tryCatchPattern":"try { zone.AddRecord(record); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"use SetRecords()\"))\n{ Log.Error(\"Route APP records through SetRecords().\"); }","preventionTips":["Route APP through SetRecords, never AddRecord.","Exclude set-managed types from AddRecord loops.","Treat this InvalidOperationException as a caller-side bug."],"tags":["dns","record","app","invalidoperation","validation"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}