{"record":{"id":"4baa4c2b56e18602","repo":"TechnitiumSoftware/DnsServer","slug":"maxmind-database-not-initialized-4baa4c","errorCode":null,"errorMessage":"MaxMind database not initialized.","messagePattern":"MaxMind database not initialized\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Apps/GeoCountryApp/CNAME.cs","lineNumber":82,"sourceCode":"        #region public\n\n        public Task InitializeAsync(IDnsServer dnsServer, string? config)\n        {\n            _dnsServer = dnsServer;\n            _maxMind = MaxMind.Create(dnsServer);\n\n            return Task.CompletedTask;\n        }\n\n        public Task<DnsDatagram?> ProcessRequestAsync(DnsDatagram request, IPEndPoint remoteEP, DnsTransportProtocol protocol, bool isRecursionAllowed, string zoneName, string appRecordName, uint appRecordTtl, string appRecordData)\n        {\n            DnsQuestionRecord question = request.Question[0];\n\n            if (!question.Name.Equals(appRecordName, StringComparison.OrdinalIgnoreCase) && !appRecordName.StartsWith('*'))\n                return Task.FromResult<DnsDatagram?>(null);\n\n            if (_maxMind is null)\n                throw new InvalidOperationException(\"MaxMind database not initialized.\");\n\n            using JsonDocument jsonDocument = JsonDocument.Parse(appRecordData, Address._jsonParseOptions);\n            JsonElement jsonAppRecordData = jsonDocument.RootElement;\n            JsonElement jsonCountry = default;\n            string? countryCode = null;\n\n            byte scopePrefixLength = 0;\n            EDnsClientSubnetOptionData requestECS = request.GetEDnsClientSubnetOption();\n            if (requestECS is not null)\n            {\n                long? asn = null;\n\n                if ((_maxMind.IspReader is not null) && _maxMind.IspReader.TryIsp(requestECS.Address, out IspResponse? csIsp) && (csIsp.Network is not null))\n                {\n                    scopePrefixLength = (byte)csIsp.Network.PrefixLength;\n                    asn = csIsp.AutonomousSystemNumber;\n                }\n                else if ((_maxMind.AsnReader is not null) && _maxMind.AsnReader.TryAsn(requestECS.Address, out AsnResponse? csAsn) && (csAsn.Network is not null))","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/Apps/GeoCountryApp/CNAME.cs#L64-L100","documentation":"Thrown by GeoCountryApp CNAME.ProcessRequestAsync when _maxMind is null. Same root cause as error 29 but reached on a CNAME query against a country-routed record: no MaxMind reader is available, so the lookup fails with InvalidOperationException.","triggerScenarios":"A CNAME query matches a GeoCountryApp record while _maxMind is null, i.e. the country database file was absent at startup.","commonSituations":"Country database not deployed, moved, or deleted; CNAME country records then surface the failure.","solutions":["Put GeoLite2-Country.mmdb (or GeoIP2-Country.mmdb) in the ApplicationFolder.","Restart the service so the MaxMind constructor initialises _maxMind.","Confirm error 31 no longer appears at startup."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (_maxMind is null)\n    _log.Warn(\"GeoCountryApp CNAME query for {0} skipped: MaxMind database not loaded.\", appRecordName);","typeGuard":null,"tryCatchPattern":"try { return await ProcessCountryCnameAsync(request, ...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"MaxMind database not initialized\"))\n{ _log.Error(\"GeoIP country database missing — deploy GeoLite2-Country.mmdb.\"); return Task.FromResult<DnsDatagram?>(null); }","preventionTips":["Ensure the country database is present before serving CNAME country records.","Surface error 31 in operator tooling.","Add a startup readiness gate on _maxMind."],"tags":["geo","maxmind","country","cname","invalid-operation"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}