lionsoul2014/ip2region · error · FileNotFoundException
xdb file not found.
Error message
xdb file not found.
What it means
.NET FileNotFoundException from GetVersionAsync's File.Exists pre-check: the dbPath was supplied but no file exists at that location (wrong path, not-yet-created database, or working-directory mismatch in relative paths).
Source
Thrown at binding/csharp/IP2Region.Net/XDB/Util.cs:45
{
byte[] bytes = ipAddress.GetAddressBytes();
Array.Reverse(bytes);
return MemoryMarshal.Read<uint>(bytes);
}
public static uint GetMidIp(uint x, uint y)
=> (x & y) + ((x ^ y) >> 1);
public static async Task<XdbVersion> GetVersionAsync(string dbPath, CancellationToken token = default)
{
if (string.IsNullOrEmpty(dbPath))
{
throw new ArgumentNullException(nameof(dbPath));
}
if (!File.Exists(dbPath))
{
throw new FileNotFoundException("xdb file not found.", dbPath);
}
using var reader = File.OpenRead(dbPath);
return await GetVersionAsync(reader, token);
}
internal static async Task<XdbVersion> GetVersionAsync(FileStream reader, CancellationToken token = default)
{
XdbVersion ret = default;
var buffer = ArrayPool<byte>.Shared.Rent(256);
try
{
var length = await reader.ReadAsync(buffer, 0, 256, token);
if (length == 256)
{
ret = Parse(buffer);
}View on GitHub (pinned to c1a1fc7d59)
Solutions
- Verify the path is correct and the xdb file actually exists (use an absolute path to avoid cwd issues)
- Ensure the file is deployed/copied to the output directory or container image
- Create or download the xdb database before first use
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at binding/csharp/IP2Region.Net/XDB/Util.cs:45 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of lionsoul2014/ip2region@c1a1fc7d59 (2026-09-02).
Data as JSON: /api/errors/205767ec664b0adf.
Report an issue: GitHub.