FormatError on dns update

Jul 28, 2014 at 7:43 PM
I am able to query records, simple enough. When trying to update a Microsoft DNS server that is or is not AD integrated (have tried both) and setup as allow secure or non-secure, I still get the return code of format error. Is there some other information this library provides to help me understand why my input is incorrect?
class Program
    {
        private const string _sourceFQDN = "zp-dns.zpother.com";
        private const string _domainFQDN = "zpother.com";
        private const string _dnsServerIP = "172.31.202.0";
        private const string _newAddress = "172.31.202.44";
        private const string _newRecordName = "zp-test.zpother.com";


        static void Main(string[] args)
        {
            Console.WriteLine("Begin DNS test");
            Console.ReadLine();

            DnsClient dnsServer = new DnsClient(IPAddress.Parse(_dnsServerIP), 5000);

            DnsMessage queryMsg = dnsServer.Resolve(_sourceFQDN);

            IAddressRecord firstRecord = queryMsg.AnswerRecords.First() as IAddressRecord;

            Console.WriteLine(firstRecord.Address);

            DnsUpdateMessage msg = new DnsUpdateMessage
            {
                ZoneName = _domainFQDN
            };

            msg.Updates.Add(new AddRecordUpdate(new ARecord(_newRecordName, 300, IPAddress.Parse(_newAddress))));

            DnsUpdateMessage dnsResult = dnsServer.SendUpdate(msg);

            Console.WriteLine("Return code: " + dnsResult.ReturnCode.ToString() + Environment.NewLine + "Press any key to continue...");
            Console.ReadLine();
        }
    }
Jul 29, 2014 at 1:50 PM
https://arsofttoolsnet.codeplex.com/discussions/350710

pi314's post is what helped me. Setting the first "Question" to a zone class of INet instead of Any worked

Here is what worked for me:
class Program
    {
        private const string _sourceFQDN = "zp-dns.zpother.com";
        private const string _domainFQDN = "zpother.com";
        private const string _dnsServerIP = "172.31.202.0";
        private const string _newAddress = "172.31.202.44";
        private const string _newRecordName = "zp-test.zpother.com";


        static void Main(string[] args)
        {
            Console.WriteLine("Begin DNS test");
            Console.ReadLine();

            DnsClient dnsServer = new DnsClient(IPAddress.Parse(_dnsServerIP), 5000);

            DnsMessage queryMsg = dnsServer.Resolve(_sourceFQDN);

            IAddressRecord firstRecord = queryMsg.AnswerRecords.First() as IAddressRecord;

            Console.WriteLine(firstRecord.Address);

            MyDNSMessage msg = new MyDNSMessage
            {
                ZoneName = _domainFQDN
            };

            msg.ZoneClass = RecordClass.INet;

            msg.Updates.Add(new AddRecordUpdate(new ARecord(_newRecordName, 300, IPAddress.Parse(_newAddress))));

            DnsUpdateMessage dnsResult = dnsServer.SendUpdate(msg);

            Console.WriteLine("Return code: " + dnsResult.ReturnCode.ToString() + Environment.NewLine + "Press any key to continue...");
            Console.ReadLine();
        }
    }

    public class MyDNSMessage : DnsUpdateMessage
    {
        public RecordClass ZoneClass
        {
            get { return Questions.Count > 0 ? Questions[0].RecordClass : RecordClass.Any; }
            set
            {
                if (string.IsNullOrEmpty(ZoneName))
                    throw new ArgumentException("Provide the zone first");

                DnsQuestion modified = new DnsQuestion(Questions[0].Name, Questions[0].RecordType, value);

                Questions.Remove(Questions[0]);

                Questions.Add(modified);
            }
        }
    }