{"record":{"id":"cccc26bacff95c9b","repo":"TechnitiumSoftware/DnsServer","slug":"maxmind-database-not-initialized-cccc26","errorCode":null,"errorMessage":"MaxMind database not initialized.","messagePattern":"MaxMind database not initialized\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Apps/GeoDistanceApp/Address.cs","lineNumber":106,"sourceCode":"            _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            switch (question.Type)\n            {\n                case DnsResourceRecordType.A:\n                case DnsResourceRecordType.AAAA:\n                    if (_maxMind is null)\n                        throw new InvalidOperationException(\"MaxMind database not initialized.\");\n\n                    Location? location = null;\n\n                    byte scopePrefixLength = 0;\n                    EDnsClientSubnetOptionData requestECS = request.GetEDnsClientSubnetOption();\n                    if (requestECS is not null)\n                    {\n                        if ((_maxMind.IspReader is not null) && _maxMind.IspReader.TryIsp(requestECS.Address, out IspResponse? csIsp) && (csIsp.Network is not null))\n                            scopePrefixLength = (byte)csIsp.Network.PrefixLength;\n                        else if ((_maxMind.AsnReader is not null) && _maxMind.AsnReader.TryAsn(requestECS.Address, out AsnResponse? csAsn) && (csAsn.Network is not null))\n                            scopePrefixLength = (byte)csAsn.Network.PrefixLength;\n                        else\n                            scopePrefixLength = requestECS.SourcePrefixLength;\n\n                        if (_maxMind.CityReader.TryCity(requestECS.Address, out CityResponse? csResponse) && csResponse.Location.HasCoordinates)\n                            location = csResponse.Location;\n                    }\n","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/Apps/GeoDistanceApp/Address.cs#L88-L124","documentation":"Thrown by GeoDistanceApp Address.ProcessRequestAsync in the A/AAAA branch when _maxMind is null. GeoDistanceApp uses a City-level MaxMind database to compute the closest backend; if that database was not loaded at startup (see error 34), the field stays null and any distance lookup raises InvalidOperationException.","triggerScenarios":"A DNS A/AAAA query matches a GeoDistanceApp record, but the MaxMind reader is null because the City database file was missing at startup.","commonSituations":"GeoDistanceApp deployed without the GeoLite2/GeoIP2-City.mmdb file, or the file removed/moved. Distance-based answers fail for all clients.","solutions":["Deploy GeoLite2-City.mmdb (or GeoIP2-City.mmdb) to the ApplicationFolder.","Restart the DnsServer service so the MaxMind constructor runs successfully.","Confirm the startup log no longer reports 'MaxMind City file is missing!' (error 34)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (_maxMind is null)\n    _log.Warn(\"GeoDistanceApp A/AAAA query for {0} skipped: MaxMind City database not loaded.\", appRecordName);","typeGuard":null,"tryCatchPattern":"try { return await ProcessDistanceAsync(request, ...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"MaxMind database not initialized\"))\n{ _log.Error(\"GeoIP City database missing — deploy GeoLite2-City.mmdb.\"); return Task.FromResult<DnsDatagram?>(null); }","preventionTips":["Deploy the City database (not just Country) for GeoDistanceApp.","Fail fast at startup if the MaxMind reader is null.","Monitor for error 34 at startup."],"tags":["geo","maxmind","distance","city","invalid-operation"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}