{"record":{"id":"fddb91219ae037be","repo":"BornToBeRoot/NETworkManager","slug":"dns-client-is-not-configured-call-configure-first","errorCode":null,"errorMessage":"DNS client is not configured. Call Configure() first.","messagePattern":"DNS client is not configured\\. Call Configure\\(\\) first\\.","errorType":"exception","errorClass":"DNSClientNotConfiguredException","httpStatus":null,"severity":"error","filePath":"Source/NETworkManager.Utilities/DNSClient.cs","lineNumber":90,"sourceCode":"        Log.Debug(addSuffix\n            ? $\"Configure - DNS suffix will be added to hostnames without a dot: {settings.DNSSuffix}\"\n            : \"Configure - DNS suffix will NOT be added to hostnames without a dot.\");\n\n        _state = new ResolverState(client, addSuffix, settings);\n\n        Log.Debug(\"Configure - DNS client configured.\");\n        _isConfigured = true;\n    }\n\n    /// <summary>\n    ///     Resolve an IPv4 address from a hostname or FQDN.\n    /// </summary>\n    /// <param name=\"query\">Hostname or FQDN as string like \"example.com\".</param>\n    /// <returns><see cref=\"IPAddress\" /> of the host.</returns>\n    public async Task<DNSClientResultIPAddress> ResolveAAsync(string query)\n    {\n        if (!_isConfigured)\n            throw new DNSClientNotConfiguredException(NotConfiguredMessage);\n\n        var state = _state;\n\n        query = AddDNSSuffixIfConfigured(query, state);\n\n        try\n        {\n            var result = await state.Client.QueryAsync(query, QueryType.A);\n\n            // Pass the error we got from the lookup client (dns server).\n            // NXDOMAIN is not a real failure like a timeout - flag it via IsNotFound so callers can\n            // treat it as \"no record\". SERVFAIL/REFUSED are not included here: for a forward lookup\n            // they mean the resolver actually failed or refused the query, not \"record does not exist\".\n            if (result.HasError)\n                return new DNSClientResultIPAddress(result.HasError, result.ErrorMessage, $\"{result.NameServer}\")\n                { IsNotFound = IsNotFoundResponseCode(result.Header.ResponseCode) };\n\n            // Validate result because of https://github.com/BornToBeRoot/NETworkManager/issues/1934","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/BornToBeRoot/NETworkManager/blob/2780d65469917a296dbc15f206107d72e2d0115c/Source/NETworkManager.Utilities/DNSClient.cs#L72-L108","documentation":"DNSClient.ResolveAAsync performs an A record lookup, but the client must first be initialized with Configure() (which creates the internal LookupClient and state). If _isConfigured is false, it throws DNSClientNotConfiguredException with the message 'DNS client is not configured. Call Configure() first.'","triggerScenarios":"Calling ResolveAAsync on a newly constructed DNSClient instance without ever calling Configure(), or after reconfiguration logic failed to run / was skipped on the initialization path.","commonSituations":"Instantiating DNSClient in a new ViewModel/tool without wiring the app's Configure call (which reads DNS servers from settings); using the client in a unit test without setup; calling resolve before settings load completes.","solutions":["Call Configure() (with the desired DNS servers, or none for system defaults) before any Resolve* call","Ensure the application's initialization path that configures DNSClient actually runs before DNS-dependent features","Guard call sites: expose an IsConfigured check or lazily call Configure on first use","In tests, configure the client in the fixture setup"],"exampleFix":"// before\nvar dns = new DNSClient();\nvar result = await dns.ResolveAAsync(\"example.com\"); // throws\n// after\nvar dns = new DNSClient();\ndns.Configure();\nvar result = await dns.ResolveAAsync(\"example.com\");","handlingStrategy":"try-catch","validationCode":"if (!_dnsClient.IsConfigured) _dnsClient.Configure();","typeGuard":"bool ReadyForQueries(DNSClient c) => c != null && c.IsConfigured;","tryCatchPattern":"try { var r = await dns.ResolveAAsync(query); }\ncatch (DNSClientNotConfiguredException) { dns.Configure(); var r = await dns.ResolveAAsync(query); }","preventionTips":["Configure the client during application startup","Use a single shared, configured DNSClient instance","Write tests that configure the client in setup","Keep Configure() idempotent so retrying is safe"],"tags":["dns","initialization","network"],"backgroundTag":"missing-required-config","analyzedSha":"2780d65469917a296dbc15f206107d72e2d0115c","analyzedAt":"2026-09-12T17:00:17.986Z","contentChangedAt":"2026-09-12T17:00:17.986Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}