dotnet/AspNetCore.Docs · critical · InvalidOperationException

No server address available.

Error message

No server address available.

What it means

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.

Source

Thrown at aspnetcore/blazor/fundamentals/signalr.md:1861

@using Microsoft.AspNetCore.SignalR.Client
@inject IHostEnvironment Environment
@inject IServer Server

...

@code {
    private HubConnection? hubConnection;

    protected override async Task OnInitializedAsync()
    {
        var serverAddress = Server.Features
           .Get<IServerAddressesFeature>()?
           .Addresses
           .FirstOrDefault(a => a.StartsWith("http://") || a.StartsWith("https://"));

        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.");
            }

View on GitHub (pinned to c67a80103a)

Solutions

  1. Ensure the app is actually running under Kestrel/HTTPSYS with explicit http(s) URLs (UseUrls, Kestrel endpoints, or ASPNETCORE_URLS env var).
  2. If testing, fall back to a configured base address (e.g. from IConfiguration) instead of probing IServerAddressesFeature.
  3. Move the address lookup to OnInitializedAsync/OnAfterRenderAsync where the server is guaranteed running, not into earlier lifecycle stages.
  4. Provide a fallback Uri from configuration when the feature is unavailable.

Example fix

// before
var serverAddress = Server.Features
   .Get<IServerAddressesFeature>()?
   .Addresses
   .FirstOrDefault(a => a.StartsWith("http://") || a.StartsWith("https://"));

if (serverAddress is null)
{
    throw new InvalidOperationException("No server address available.");
}

// after — fall back to configuration
var serverAddress = Server.Features
       .Get<IServerAddressesFeature>()?
       .Addresses
       .FirstOrDefault(a => a.StartsWith("http://") || a.StartsWith("https://"))
    ?? builder.Configuration["HubBaseUrl"];

if (string.IsNullOrWhiteSpace(serverAddress))
{
    throw new InvalidOperationException(
        "No server address available. Configure 'HubBaseUrl' or set ASPNETCORE_URLS.");
}
Defensive patterns

Strategy: validation

Validate before calling

var serverAddress = Server.Features.Get<IServerAddressesFeature>()?
    .Addresses.FirstOrDefault(a => a.StartsWith("http://") || a.StartsWith("https://"))
    ?? Configuration["HubBaseUrl"];
if (string.IsNullOrWhiteSpace(serverAddress)) {
    /* set safe default or skip hub init */
}

Type guard

static bool HasHttpAddress(IServerAddressesFeature? f) =>
    f?.Addresses.Any(a => a.StartsWith("http://") || a.StartsWith("https://")) == true;

Try / catch

try { /* OnInitializedAsync hub setup */ }
catch (InvalidOperationException ex) when (ex.Message.Contains("server address"))
{
    logger.LogError(ex, "Could not discover server address; configure HubBaseUrl.");
    hubConnection = null;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/AspNetCore.Docs@c67a80103a (2026-08-13). Data as JSON: /api/errors/fc469c2efc2dd1ac. Report an issue: GitHub.