TechnitiumSoftware/DnsServer · error · InvalidOperationException

MaxMind database not initialized.

Error message

MaxMind database not initialized.

What it means

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.

Source

Thrown at Apps/GeoDistanceApp/Address.cs:106

            _dnsServer = dnsServer;
            _maxMind = MaxMind.Create(dnsServer);

            return Task.CompletedTask;
        }

        public Task<DnsDatagram?> ProcessRequestAsync(DnsDatagram request, IPEndPoint remoteEP, DnsTransportProtocol protocol, bool isRecursionAllowed, string zoneName, string appRecordName, uint appRecordTtl, string appRecordData)
        {
            DnsQuestionRecord question = request.Question[0];

            if (!question.Name.Equals(appRecordName, StringComparison.OrdinalIgnoreCase) && !appRecordName.StartsWith('*'))
                return Task.FromResult<DnsDatagram?>(null);

            switch (question.Type)
            {
                case DnsResourceRecordType.A:
                case DnsResourceRecordType.AAAA:
                    if (_maxMind is null)
                        throw new InvalidOperationException("MaxMind database not initialized.");

                    Location? location = null;

                    byte scopePrefixLength = 0;
                    EDnsClientSubnetOptionData requestECS = request.GetEDnsClientSubnetOption();
                    if (requestECS is not null)
                    {
                        if ((_maxMind.IspReader is not null) && _maxMind.IspReader.TryIsp(requestECS.Address, out IspResponse? csIsp) && (csIsp.Network is not null))
                            scopePrefixLength = (byte)csIsp.Network.PrefixLength;
                        else if ((_maxMind.AsnReader is not null) && _maxMind.AsnReader.TryAsn(requestECS.Address, out AsnResponse? csAsn) && (csAsn.Network is not null))
                            scopePrefixLength = (byte)csAsn.Network.PrefixLength;
                        else
                            scopePrefixLength = requestECS.SourcePrefixLength;

                        if (_maxMind.CityReader.TryCity(requestECS.Address, out CityResponse? csResponse) && csResponse.Location.HasCoordinates)
                            location = csResponse.Location;
                    }

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Deploy GeoLite2-City.mmdb (or GeoIP2-City.mmdb) to the ApplicationFolder.
  2. Restart the DnsServer service so the MaxMind constructor runs successfully.
  3. Confirm the startup log no longer reports 'MaxMind City file is missing!' (error 34).
Defensive patterns

Strategy: try-catch

Validate before calling

if (_maxMind is null)
    _log.Warn("GeoDistanceApp A/AAAA query for {0} skipped: MaxMind City database not loaded.", appRecordName);

Try / catch

try { return await ProcessDistanceAsync(request, ...); }
catch (InvalidOperationException ex) when (ex.Message.Contains("MaxMind database not initialized"))
{ _log.Error("GeoIP City database missing — deploy GeoLite2-City.mmdb."); return Task.FromResult<DnsDatagram?>(null); }

Prevention

When it happens

Trigger: A DNS A/AAAA query matches a GeoDistanceApp record, but the MaxMind reader is null because the City database file was missing at startup.

Common situations: GeoDistanceApp deployed without the GeoLite2/GeoIP2-City.mmdb file, or the file removed/moved. Distance-based answers fail for all clients.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/cccc26bacff95c9b. Report an issue: GitHub.