Skip to content

LookupClientOptions name servers should not be read-only #160

Closed

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,
            };

Activity

  1. MichaConrad commented on May 11, 2022

    @MichaConrad
    Collaborator

    That's by design and those properties are immutable for good reason.

    Your use case is a different one, you want to call multiple different servers? Then just use the .QueryServer overloads which have options to specify a different server (and options) each call.

  2. locked and limited conversation to collaborators on May 11, 2022
  3. converted this issue into a discussion #161 on May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions