dotnet/AspNetCore.Docs · critical · InvalidOperationException
No suitable IP address.
Error message
No suitable IP address.
What it means
InvalidOperationException thrown after wildcard address substitution fails. When Kestrel is bound to a wildcard (0.0.0.0, [::], +, *) the code resolves a real IP via Dns.GetHostAddressesAsync(MachineName) and picks the first non-loopback IPv4 address. If none is found it throws because there is no concrete IP to point the HubConnection at.
Source
Thrown at aspnetcore/blazor/fundamentals/signalr.md:1877
if (serverAddress is null)
{
throw new InvalidOperationException("No server address available.");
}
var uri = new UriBuilder(serverAddress + "/chathub");
// If Kestrel is bound to a wildcard, substitute a real IP
if (uri.Host is "0.0.0.0" or "[::]" or "+" or "*")
{
var addresses = await Dns.GetHostAddressesAsync(
System.Environment.MachineName);
var ip = addresses.FirstOrDefault(a =>
a.AddressFamily == AddressFamily.InterNetwork
&& !IPAddress.IsLoopback(a));
if (ip is null)
{
throw new InvalidOperationException("No suitable IP address.");
}
uri.Host = ip.ToString();
}
hubConnection = new HubConnectionBuilder()
.WithUrl(uri.Uri)
.Build();
hubConnection.On<ChatMessage>("ReceiveMessage", (message) =>
{
...
});
await hubConnection.StartAsync();
}
}
```View on GitHub (pinned to c67a80103a)
Solutions
- Configure the hub base URL explicitly via configuration rather than resolving from MachineName.
- Bind Kestrel to a specific IP instead of a wildcard so no substitution is needed.
- Relax the filter to also accept IPv6 (AddressFamily.InterNetworkV6) when the host is IPv6-capable.
- Ensure the hostname resolves to a non-loopback address (DNS/hosts file) before running.
Example fix
// before
var ip = addresses.FirstOrDefault(a =>
a.AddressFamily == AddressFamily.InterNetwork
&& !IPAddress.IsLoopback(a));
if (ip is null)
{
throw new InvalidOperationException("No suitable IP address.");
}
// after — accept IPv4 or IPv6, fall back to config
var ip = addresses.FirstOrDefault(a =>
(a.AddressFamily == AddressFamily.InterNetwork
|| a.AddressFamily == AddressFamily.InterNetworkV6)
&& !IPAddress.IsLoopback(a));
if (ip is null)
{
var configured = builder.Configuration["HubHostIp"];
if (string.IsNullOrWhiteSpace(configured)
|| !IPAddress.TryParse(configured, out var parsed))
{
throw new InvalidOperationException(
"No suitable IP address. Set 'HubHostIp' in configuration.");
}
ip = parsed;
} Defensive patterns
Strategy: validation
Validate before calling
var addresses = await Dns.GetHostAddressesAsync(Environment.MachineName);
var ip = addresses.FirstOrDefault(a =>
(a.AddressFamily is AddressFamily.InterNetwork or AddressFamily.InterNetworkV6)
&& !IPAddress.IsLoopback(a));
if (ip is null && IPAddress.TryParse(Configuration["HubHostIp"], out var cfg)) ip = cfg; Type guard
static bool HasNonLoopbackIPv4(IPAddress[] addrs) =>
addrs.Any(a => a.AddressFamily == AddressFamily.InterNetwork && !IPAddress.IsLoopback(a)); Try / catch
try { /* resolve IP */ }
catch (InvalidOperationException ex) when (ex.Message.Contains("suitable IP"))
{
logger.LogError(ex, "No suitable host IP; set HubHostIp in configuration.");
} Prevention
- Bind Kestrel to a specific IP rather than a wildcard.
- Configure the hub host IP explicitly for containerized hosts.
- Accept IPv6 candidates in addition to IPv4.
- Ensure the hostname resolves to a non-loopback address.
When it happens
Trigger: Containerized or sandboxed host where DNS resolution of MachineName returns only loopback (127.0.0.1) or only IPv6 addresses; machines whose hostname does not resolve to an IPv4 address; environments where GetHostAddressesAsync returns an empty list.
Common situations: Running in Docker/Kubernetes with a hostname that does not resolve on the container network; CI runners with minimal networking; binding Kestrel to '+' on a host with no external IPv4 interface; IPv6-only hosts.
Related errors
- No server address available.
- Unable to bind DOM element: ${id}
- QR code size must be less than {MaxQrSize}.
- worker exports not loaded
- Unknown command: ${e.data.command}
AI-assisted analysis of dotnet/AspNetCore.Docs@c67a80103a (2026-08-13).
Data as JSON: /api/errors/d0f19d8a981da3dc.
Report an issue: GitHub.