iOfficeAI/OfficeCLI · error · ArgumentException
Could not resolve host '{host}'.
Error message
Could not resolve host '{host}'. What it means
Thrown by the guarded ConnectCallback when DNS returned an empty address list for the host (addresses.FirstOrDefault() is null). It is a fallback: GetHostAddressesAsync usually throws outright on NXDOMAIN, but this guard catches the empty-result case so a no-address host produces a clear message rather than a NullReferenceException downstream.
Source
Thrown at src/officecli/Core/SsrfGuard.cs:54
public static SocketsHttpHandler CreateGuardedHandler(string what)
{
return new SocketsHttpHandler
{
AllowAutoRedirect = true,
MaxAutomaticRedirections = 10,
ConnectCallback = async (ctx, ct) =>
{
var host = ctx.DnsEndPoint.Host;
var addresses = await Dns.GetHostAddressesAsync(host, ct).ConfigureAwait(false);
foreach (var addr in addresses)
{
if (!IsPublicAddress(addr))
throw new ArgumentException(
$"Refusing to fetch {what} from non-public address '{addr}' (host '{host}'). " +
$"Remote {what} sources must resolve to a public IP (SSRF protection).");
}
var target = addresses.FirstOrDefault()
?? throw new ArgumentException($"Could not resolve host '{host}'.");
var socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
try
{
await socket.ConnectAsync(target, ctx.DnsEndPoint.Port, ct).ConfigureAwait(false);
return new NetworkStream(socket, ownsSocket: true);
}
catch
{
socket.Dispose();
throw;
}
}
};
}
/// <summary>
/// Shared cap on a single remote fetch, to bound memory use on a hostile or
/// accidentally-huge response. Without it the default HttpClient bufferingView on GitHub (pinned to 1ced45e900)
Solutions
- Verify the hostname with `nslookup` / `dig` from the same machine.
- Correct the typo or use the fully-qualified domain name.
- Check network connectivity and DNS configuration.
Example fix
// before picture = "https://exmaple.com/x.png" // typo: exmaple // after picture = "https://example.com/x.png"
Defensive patterns
Strategy: try-catch
Validate before calling
async Task<bool> HostResolves(string url)
{
try { return (await System.Net.Dns.GetHostAddressesAsync(new Uri(url).Host)).Length > 0; }
catch { return false; }
} Try / catch
try { bytes = await client.GetByteArrayAsync(url); }
catch (System.ArgumentException ex) when (ex.Message.Contains("Could not resolve host"))
{ /* hostname has no DNS records; fix the URL */ }
catch (System.Net.Sockets.SocketException) { /* NXDOMAIN / network error */ } Prevention
- Validate hostnames at input time (well-formed, resolvable).
- Provide a clear 'image not reachable' path in your UI/agent for network failures.
When it happens
Trigger: An image=/file= URL whose hostname does not resolve (typo, non-existent domain), or DNS returned zero A/AAAA records.
Common situations: Typo in the hostname; DNS not configured / offline; the host is a short name that only resolves inside a specific network.
Understand the failure class
- DNS resolution errors: ENOTFOUND and getaddrinfo failures — how hostname lookups fail and how to debug them.
Related errors
- Refusing to fetch {what} from non-public address '{addr}' (h
- Remote {what} at {url} exceeds {max / (1024 * 1024)} MB limi
- Checksum mismatch for ${asset} (expected ${expected}, got ${
- Could not download OfficeCLI binary (${asset} @ ${TAG}). Las
- officecli install failed. Run manually: irm ${INSTALL_PS
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/00494274af3ebaeb.
Report an issue: GitHub.