Skip to content

LookupClientOptions name servers should not be read-only #160

@dchauran

Description

@dchauran

I am trying to use the DnsClient to validate DNS entries agianst different sets of name servers or the client's default name servers.

In all of these cases, the LookupClientOptions are the same, but the servers are not. I have a common function to create the client with the correct options, but since the name servers in the LookupClientOptions are read-only, this requires a rather ugly workaround:

            if (nameServerIps.Count > 0)
            {
                dnsClientOptions = new LookupClientOptions(nameServerIps.ToArray());
            }
            else
            {
                dnsClientOptions = new LookupClientOptions();
            }

            dnsClientOptions.UseTcpFallback = false;
            dnsClientOptions.UseCache = false;
            dnsClientOptions.EnableAuditTrail = true;
            dnsClientOptions.Timeout = new TimeSpan(Settings.QueryTimeoutMs * TimeSpan.TicksPerMillisecond);
            dnsClientOptions.Recursion = !authoritative;
            dnsClientOptions.AutoResolveNameServers = nameServerIps.Count > 0 ? false : true;
            dnsClientOptions.ContinueOnDnsError = false;
            dnsClientOptions.ThrowDnsErrors = false;

as opposed to a more elegant:

            dnsClientOptions = new LookupClientOptions()
            {
                NameServers = nameServerIps.ToArray(),
                UseTcpFallback = false,
                UseCache = false,
                EnableAuditTrail = true,
                Timeout = new TimeSpan(Settings.QueryTimeoutMs * TimeSpan.TicksPerMillisecond),
                Recursion = !authoritative,
                AutoResolveNameServers = nameServerIps.Count > 0 ? false : true,
                ContinueOnDnsError = false,
                ThrowDnsErrors = false,
            };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions