{"record":{"id":"a4c840ba0066d6c3","repo":"TechnitiumSoftware/DnsServer","slug":"maxmind-database-not-initialized-a4c840","errorCode":null,"errorMessage":"MaxMind database not initialized.","messagePattern":"MaxMind database not initialized\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Apps/GeoDistanceApp/CNAME.cs","lineNumber":99,"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            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":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/Apps/GeoDistanceApp/CNAME.cs#L81-L117","documentation":"Thrown by GeoDistanceApp CNAME.ProcessRequestAsync when _maxMind is null. CNAME counterpart of error 32: without a MaxMind reader the distance calculation cannot run and the lookup raises InvalidOperationException.","triggerScenarios":"A CNAME query matches a GeoDistanceApp record while _maxMind is null, i.e. the City database file was missing at startup.","commonSituations":"City database not deployed or removed; CNAME distance records then fail.","solutions":["Place GeoLite2-City.mmdb (or GeoIP2-City.mmdb) in the ApplicationFolder.","Restart the service so the MaxMind constructor initialises _maxMind.","Verify error 34 does not reappear at startup."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (_maxMind is null)\n    _log.Warn(\"GeoDistanceApp CNAME query for {0} skipped: MaxMind City database not loaded.\", appRecordName);","typeGuard":null,"tryCatchPattern":"try { return await ProcessDistanceCnameAsync(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":["Ensure the City database is present before serving CNAME distance records.","Track error 34 in startup diagnostics.","Add a readiness check on _maxMind."],"tags":["geo","maxmind","distance","cname","invalid-operation"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}