{"record":{"id":"fc469c2efc2dd1ac","repo":"dotnet/AspNetCore.Docs","slug":"no-server-address-available","errorCode":null,"errorMessage":"No server address available.","messagePattern":"No server address available\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"aspnetcore/blazor/fundamentals/signalr.md","lineNumber":1861,"sourceCode":"@using Microsoft.AspNetCore.SignalR.Client\n@inject IHostEnvironment Environment\n@inject IServer Server\n\n...\n\n@code {\n    private HubConnection? hubConnection;\n\n    protected override async Task OnInitializedAsync()\n    {\n        var serverAddress = Server.Features\n           .Get<IServerAddressesFeature>()?\n           .Addresses\n           .FirstOrDefault(a => a.StartsWith(\"http://\") || a.StartsWith(\"https://\"));\n\n        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","sourceCodeStart":1843,"sourceCodeEnd":1879,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/blazor/fundamentals/signalr.md#L1843-L1879","documentation":"InvalidOperationException thrown during OnInitializedAsync when the Blazor Server component cannot find an http:// or https:// address from IServerAddressesFeature. The component uses Server.Features.Get<IServerAddressesFeature>()?.Addresses to discover the current base URL for building the SignalR /chathub Uri; if no qualifying address is present the connection cannot be formed.","triggerScenarios":"Running the host where IServerAddressesFeature is absent (e.g. testing in a context without a running Kestrel server), or the server is bound only to addresses that do not start with http:// or https://. Can occur in test hosts, in-process test servers, or when the feature has not been populated yet at component init time.","commonSituations":"Using WebApplicationFactory/TestServer which may not expose IServerAddressesFeature the same way; binding Kestrel only to a named pipe or unix socket; reading the feature too early in the pipeline before addresses are configured; misconfigured UseUrls/UseSetting for addresses.","solutions":["Ensure the app is actually running under Kestrel/HTTPSYS with explicit http(s) URLs (UseUrls, Kestrel endpoints, or ASPNETCORE_URLS env var).","If testing, fall back to a configured base address (e.g. from IConfiguration) instead of probing IServerAddressesFeature.","Move the address lookup to OnInitializedAsync/OnAfterRenderAsync where the server is guaranteed running, not into earlier lifecycle stages.","Provide a fallback Uri from configuration when the feature is unavailable."],"exampleFix":"// before\nvar serverAddress = Server.Features\n   .Get<IServerAddressesFeature>()?\n   .Addresses\n   .FirstOrDefault(a => a.StartsWith(\"http://\") || a.StartsWith(\"https://\"));\n\nif (serverAddress is null)\n{\n    throw new InvalidOperationException(\"No server address available.\");\n}\n\n// after — fall back to configuration\nvar serverAddress = Server.Features\n       .Get<IServerAddressesFeature>()?\n       .Addresses\n       .FirstOrDefault(a => a.StartsWith(\"http://\") || a.StartsWith(\"https://\"))\n    ?? builder.Configuration[\"HubBaseUrl\"];\n\nif (string.IsNullOrWhiteSpace(serverAddress))\n{\n    throw new InvalidOperationException(\n        \"No server address available. Configure 'HubBaseUrl' or set ASPNETCORE_URLS.\");\n}","handlingStrategy":"validation","validationCode":"var serverAddress = Server.Features.Get<IServerAddressesFeature>()?\n    .Addresses.FirstOrDefault(a => a.StartsWith(\"http://\") || a.StartsWith(\"https://\"))\n    ?? Configuration[\"HubBaseUrl\"];\nif (string.IsNullOrWhiteSpace(serverAddress)) {\n    /* set safe default or skip hub init */\n}","typeGuard":"static bool HasHttpAddress(IServerAddressesFeature? f) =>\n    f?.Addresses.Any(a => a.StartsWith(\"http://\") || a.StartsWith(\"https://\")) == true;","tryCatchPattern":"try { /* OnInitializedAsync hub setup */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"server address\"))\n{\n    logger.LogError(ex, \"Could not discover server address; configure HubBaseUrl.\");\n    hubConnection = null;\n}","preventionTips":["Configure http(s) URLs via UseUrls/ASPNETCORE_URLS/Kestrel endpoints.","Provide a configuration fallback for the hub base URL.","Resolve the address in OnInitializedAsync after the server is running.","Avoid this code path under test hosts lacking IServerAddressesFeature."],"tags":["blazor","signalr","kestrel","iserveraddressesfeature","configuration"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}