MaxMind.Db 5.2.0

Prefix Reserved
dotnet add package MaxMind.Db --version 5.2.0
                    
NuGet\Install-Package MaxMind.Db -Version 5.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MaxMind.Db" Version="5.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MaxMind.Db" Version="5.2.0" />
                    
Directory.Packages.props
<PackageReference Include="MaxMind.Db" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MaxMind.Db --version 5.2.0
                    
#r "nuget: MaxMind.Db, 5.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MaxMind.Db@5.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MaxMind.Db&version=5.2.0
                    
Install as a Cake Addin
#tool nuget:?package=MaxMind.Db&version=5.2.0
                    
Install as a Cake Tool

MaxMind DB Reader

NuGet

Description

This is the .NET API for reading MaxMind DB files. MaxMind DB is a binary file format that stores data indexed by IP address subnets (IPv4 or IPv6).

Installation

NuGet

We recommend installing this library with NuGet. To do this, type the following into the Visual Studio Package Manager Console:

install-package MaxMind.Db

Usage

Note: For accessing MaxMind GeoIP databases, we generally recommend using the GeoIP .NET API rather than using this package directly.

To use the API, you must first create a Reader object. The constructor for the reader object takes a string with the path to the MaxMind DB file. Optionally you may pass a second parameter with a FileAccessMode enum with the value MemoryMapped or Memory. The default mode is MemoryMapped, which maps the file to virtual memory. This often provides performance comparable to loading the file into real memory with the Memory mode while using significantly less memory.

To look up an IP address, pass a System.Net.IPAddress object to the Find<T> method on Reader. This method will return the result as type T. T may either be a generic collection, a class using the [MaxMind.Db.Constructor] attribute to declare which constructor to use during deserialization, or a class with [MaxMind.Db.MapKey("name")]-annotated init properties for property-based activation.

We recommend reusing the Reader object rather than creating a new one for each lookup. The creation of this object is relatively expensive as it must read in metadata for the file.

Example Decoding to a Dictionary


using (var reader = new Reader("GeoIP2-City.mmdb"))
{
    var ip = IPAddress.Parse("24.24.24.24");
    var data = reader.Find<Dictionary<string, object>>(ip);
    ...
}

Example Decoding to a Model Class (Constructor-Based)

using MaxMind.Db;
using System.Net;

namespace MyCode
{
    public class Asn
    {
        [Constructor]
        public Asn(
            // The MapKey attribute tells the reader to map the database
            // key to the specified constructor parameter or property.
            [MapKey("autonomous_system_number")] long? autonomousSystemNumber,
            [MapKey("autonomous_system_organization")] string autonomousSystemOrganization,

            // The Inject attribute allows you to inject arbitrary values
            // when deserializing.
            [Inject("ip_address")] IPAddress ipAddress,

            // The Network attribute tells the reader to set the constructor
            // parameter to be the network associated with the record in the
            // database.
            [Network] Network network)
        {
          ...
        }

        ...
    }


    public class Program
    {
        private static void Main(string[] args)
        {
            using (var reader = new Reader("GeoLite2-ASN.mmdb"))
            {
                var ip = IPAddress.Parse("24.24.24.24");
                var injectables = new InjectableValues();
                injectables.AddValue("ip_address", ip);
                var data = reader.Find<Asn>(ip, injectables);
                ...
            }
        }
    }
}

Example Decoding to a Model Class (Property-Based)

As an alternative to constructor-based activation, you can use init properties. This does not require a [Constructor]-annotated constructor.

using MaxMind.Db;
using System.Net;

namespace MyCode
{
    public class Asn
    {
        [MapKey("autonomous_system_number")]
        public long? AutonomousSystemNumber { get; init; }

        [MapKey("autonomous_system_organization")]
        public string? AutonomousSystemOrganization { get; init; }

        [Inject("ip_address")]
        public IPAddress? IpAddress { get; init; }

        [Network]
        public Network? Network { get; init; }
    }

    public class Program
    {
        private static void Main(string[] args)
        {
            using (var reader = new Reader("GeoLite2-ASN.mmdb"))
            {
                var ip = IPAddress.Parse("24.24.24.24");
                var injectables = new InjectableValues();
                injectables.AddValue("ip_address", ip);
                var data = reader.Find<Asn>(ip, injectables);
                ...
            }
        }
    }
}

Multi-Threaded Use

This API fully supports use in multi-threaded applications. In such applications, we suggest creating one Reader object and sharing that among threads.

NativeAOT and Trimming

The MaxMind.Db NuGet package includes a C# source generator that enables trim-safe, reflection-free deserialization for NativeAOT applications. The generator is included automatically; no additional package or registration is required. It needs the .NET SDK 7.0.100 or later; an older SDK reports CS9057 and skips the generator, leaving models on the reflection fallback. The generator reports a diagnostic for any annotated model it cannot generate, in whichever project declares that model.

The generator supports both model styles shown above:

  • A non-generic model with exactly one accessible [Constructor]-annotated constructor.
  • A non-generic property-based model with an accessible parameterless constructor and accessible annotated getters and setters. Attributes on inherited properties are supported, including concrete records whose annotations are declared on an abstract base record.

Generated collection activation supports common generic interfaces such as ICollection<T>, IReadOnlyList<T>, IDictionary<TKey, TValue>, and IReadOnlyDictionary<TKey, TValue>. Concrete collection and dictionary types are supported when they implement the corresponding mutable interface and have an accessible parameterless constructor; this includes types such as LinkedList<T>. The generator discovers these types when they are model members or closed generic arguments in direct Reader.Find<T> and Reader.FindAll<T> calls.

There are several current limitations:

  • Source generation is supported for C# models. Other .NET languages continue to use the reflection fallback, which is not guaranteed to work after trimming or with NativeAOT.

  • Source generation requires C# 9 or later because generated registrations use module initializers. Earlier C# versions continue to use the reflection fallback in non-AOT builds.

  • A generic wrapper around Find<T> or FindAll<T> is fine for models. Models are registered from their declarations, not from lookup sites, so a method like T Lookup<T>(Reader reader, IPAddress address) still resolves generated activation for every model declared in a generator-enabled project.

    What such a wrapper cannot carry is a collection result type. Collection and dictionary types have no annotated declaration to find, so they are discovered from the lookup site, and a wrapper hides which one is used. Use a concrete type argument at the call site — Find<Dictionary<string, object>> rather than Lookup<Dictionary<string, object>> — or make the collection a member of a model. The same applies to a result type chosen at run time.

    No diagnostic is reported for a wrapper, because the generator cannot tell from the call site whether the eventual type argument is a registered model or an unregistered collection, and warning on every wrapper would be a false positive for the common case. A constructed type that still contains a type parameter, such as Find<Dictionary<string, T>>, is reported as MMDBSG015.

  • Generic model classes are not supported, closed or otherwise. Models are discovered from their declarations, so the generator only ever sees the unbound definition and reports MMDBSG004, even where every use is a closed construction such as Find<Wrapper<string>>.

  • Models must be classes or records. Annotated structs and record structs are reported as MMDBSG012. A constructor-based struct then falls back to reflection and works; a property-based struct or record struct fails at run time, in a plain JIT build as much as under NativeAOT, because reflection does not surface a struct's implicit parameterless constructor and there is nothing to activate unless one is declared explicitly.

  • MMDB array values cannot be deserialized into CLR array model members. Use a supported generic collection instead. byte[] remains supported for MMDB byte values.

  • Private or protected model constructors, types, property getters, and property setters cannot be called by the generated code. Use public or internal accessibility.

  • Models with required members must mark the constructor used for deserialization with SetsRequiredMembersAttribute. For property models, this is the accessible parameterless constructor.

Treat these diagnostics as build errors rather than suppressing them; each one means a model would fall back to reflection, which is not guaranteed to work after trimming or with NativeAOT. They are reported by default, including in a model class library that knows nothing about how it will be published. That is deliberate: an application's PublishAot does not propagate across a ProjectReference, so keying the diagnostics off it would silence them in the one compilation that can report them. To turn them off in a project that will never be trimmed:

<PropertyGroup>
  <MaxMindDbAotDiagnostics>false</MaxMindDbAotDiagnostics>
</PropertyGroup>

Because that property decides whether the diagnostics are produced at all, setting dotnet_diagnostic.MMDBSG0NN.severity in .editorconfig has no effect once it is false.

A separately packaged model library must be built or rebuilt with a version of MaxMind.Db that includes the source generator. Updating only the application cannot add registrations to an already compiled model assembly; precompiled model libraries without generated registrations are not guaranteed to work after trimming or with NativeAOT. The absence of a source-generator diagnostic does not validate models from an already-compiled referenced assembly. If that assembly has no generated registrations, its reflection fallback is unsupported and may fail at run time after trimming or with NativeAOT.

Format

The MaxMind DB format is an open format for quickly mapping IP addresses to records. See the specification for more information on the format.

Bug Tracker

Please report all issues with this code using the GitHub issue tracker.

If you are having an issue with a MaxMind database or service that is not specific to this reader, please contact MaxMind support.

Contributing

Patches and pull requests are encouraged. Please include unit tests whenever possible.

Versioning

The MaxMind DB Reader API uses Semantic Versioning.

This software is Copyright (c) 2013-2026 by MaxMind, Inc.

This is free software, licensed under the Apache License, Version 2.0.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (13)

Showing the top 5 NuGet packages that depend on MaxMind.Db:

Package Downloads
MaxMind.GeoIP2

MaxMind GeoIP Database Reader and Web Service Client

Dynamicweb.Admin

Package Description

NopCommerce.Core

Contains the core assemblies needed to run nopcommerce. This package only contains assemblies and can be used for package development.

MoarUtils

Useful utilities to more efficient .NET development #OnTheShouldersOfGiants

Endzone.uSplit.PersonalisationGroups

A Personalisation Groups segmentation provider for uSplit, the A/B testing plugin for Umbraco

GitHub repositories (12)

Showing the top 12 popular GitHub repositories that depend on MaxMind.Db:

Repository Stars
Archeb/opentrace
Open Source Visualized Route Tracing Tool for macOS, Windows, and Linux.
smartstore/SmartStoreNET
Open Source ASP.NET MVC Enterprise eCommerce Shopping Cart Solution
moom825/xeno-rat
Xeno-RAT is an open-source remote access tool (RAT) developed in C#, providing a comprehensive set of features for remote system management. Has features such as HVNC, live microphone, reverse proxy, and much much more!
smartstore/Smartstore
A modular, scalable and ultra-fast open-source all-in-one eCommerce platform built on ASP.NET Core 10
SparkDevNetwork/Rock
An open source CMS, Relationship Management System (RMS) and Church Management System (ChMS) all rolled into one.
wokhan/WFN
Windows Firewall Notifier extends the default Windows embedded firewall by allowing to handle and notify about outgoing connections, offers real time connections monitoring, connections map, bandwidth usage monitoring and more...
maxmind/GeoIP2-dotnet
MaxMind GeoIP2 .NET API
ZL154/JellyfinSecurity
A Jellyfin plugin that adds native two-factor authentication (TOTP, email OTP) with trusted device tokens, TV device pairing, LAN bypass, and API key bypass. Server-side enforcement — works with all clients including web, mobile, TV, and service integrations like Sonarr/Radarr.
dreling8/Nop.Framework
c# asp.net mvc base development framework from nopCommerce。
PredatH0r/SteamServerBrowser
Browse game servers and details for games using Valve's master servers
lengran/OpenPrefirePrac
An open-source CounterStrikeSharp powered server-side practicing plugin for CS2. It provides multiple prefire practices on competitive maps and support multiplayer practicing simultaneously.
skyprolk/Clash-Of-SL
Clash of SL Server (CSS) that is the fully free open source clash of clans private server and it is not affiliated to "Supercell , Oy " .
Version Downloads Last Updated
5.2.0 888 2026/9/10
5.1.0 563,008 2026/5/22
5.0.0 52,845 2026/3/12
4.3.4 926,152 2025/11/24
4.3.0 27,499 2025/11/20
4.2.0 1,142,642 2025/5/5
4.1.0 10,885,213 2023/12/5
4.0.0 5,085,803 2022/2/3
3.0.0 3,374,257 2020/11/16
2.6.1 4,523,056 2019/12/6
2.6.0 11,489 2019/12/6
2.5.0 15,353 2019/11/21
2.4.0 4,125,050 2018/4/11
2.3.0 2,254,124 2017/10/27
2.2.0 300,323 2017/5/8
2.1.3 764,717 2016/11/22
2.1.2 240,344 2016/8/8
2.1.1 16,164 2016/8/1
2.1.1-beta1 4,680 2016/6/1
2.1.0-beta4 2,381 2016/6/1
Loading failed