{"record":{"id":"d0f19d8a981da3dc","repo":"dotnet/AspNetCore.Docs","slug":"no-suitable-ip-address","errorCode":null,"errorMessage":"No suitable IP address.","messagePattern":"No suitable IP address\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"aspnetcore/blazor/fundamentals/signalr.md","lineNumber":1877,"sourceCode":"        if (serverAddress is null)\n        {\n            throw new InvalidOperationException(\"No server address available.\");\n        }\n\n        var uri = new UriBuilder(serverAddress + \"/chathub\");\n\n        // If Kestrel is bound to a wildcard, substitute a real IP\n        if (uri.Host is \"0.0.0.0\" or \"[::]\" or \"+\" or \"*\")\n        {\n            var addresses = await Dns.GetHostAddressesAsync(\n                System.Environment.MachineName);\n            var ip = addresses.FirstOrDefault(a =>\n                a.AddressFamily == AddressFamily.InterNetwork\n                && !IPAddress.IsLoopback(a));\n\n            if (ip is null)\n            {\n                throw new InvalidOperationException(\"No suitable IP address.\");\n            }\n\n            uri.Host = ip.ToString();\n        }\n\n        hubConnection = new HubConnectionBuilder()\n            .WithUrl(uri.Uri)\n            .Build();\n\n        hubConnection.On<ChatMessage>(\"ReceiveMessage\", (message) =>\n        {\n            ...\n        });\n\n        await hubConnection.StartAsync();\n    }\n}\n```","sourceCodeStart":1859,"sourceCodeEnd":1895,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/blazor/fundamentals/signalr.md#L1859-L1895","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar ip = addresses.FirstOrDefault(a =>\n    a.AddressFamily == AddressFamily.InterNetwork\n    && !IPAddress.IsLoopback(a));\n\nif (ip is null)\n{\n    throw new InvalidOperationException(\"No suitable IP address.\");\n}\n\n// after — accept IPv4 or IPv6, fall back to config\nvar ip = addresses.FirstOrDefault(a =>\n        (a.AddressFamily == AddressFamily.InterNetwork\n         || a.AddressFamily == AddressFamily.InterNetworkV6)\n        && !IPAddress.IsLoopback(a));\n\nif (ip is null)\n{\n    var configured = builder.Configuration[\"HubHostIp\"];\n    if (string.IsNullOrWhiteSpace(configured)\n        || !IPAddress.TryParse(configured, out var parsed))\n    {\n        throw new InvalidOperationException(\n            \"No suitable IP address. Set 'HubHostIp' in configuration.\");\n    }\n    ip = parsed;\n}","handlingStrategy":"validation","validationCode":"var addresses = await Dns.GetHostAddressesAsync(Environment.MachineName);\nvar ip = addresses.FirstOrDefault(a =>\n    (a.AddressFamily is AddressFamily.InterNetwork or AddressFamily.InterNetworkV6)\n    && !IPAddress.IsLoopback(a));\nif (ip is null && IPAddress.TryParse(Configuration[\"HubHostIp\"], out var cfg)) ip = cfg;","typeGuard":"static bool HasNonLoopbackIPv4(IPAddress[] addrs) =>\n    addrs.Any(a => a.AddressFamily == AddressFamily.InterNetwork && !IPAddress.IsLoopback(a));","tryCatchPattern":"try { /* resolve IP */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"suitable IP\"))\n{\n    logger.LogError(ex, \"No suitable host IP; set HubHostIp in configuration.\");\n}","preventionTips":["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."],"tags":["blazor","signalr","dns","kestrel","networking","ipv6"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}