dotnet/AspNetCore.Docs · critical · IOException

No URI!

Error message

No URI!

What it means

IOException("No URI!") thrown inline when constructing the HttpClient BaseAddress if builder.Configuration["ExternalApiUri"] is null. Unlike error 54 (which throws a generic Exception), this variant throws IOException, signaling an I/O/configuration problem with the external API endpoint. Fails at startup/DI registration so the missing URI is caught immediately.

Source

Thrown at aspnetcore/blazor/security/additional-scenarios.md:180

builder.Services.AddHttpClient("{HTTP CLIENT NAME}",
      client => client.BaseAddress = new Uri("{BASE ADDRESS}"))
      .AddHttpMessageHandler<TokenHandler>();
```

Example:

```csharp
builder.Services.AddScoped<TokenHandler>();

builder.Services.AddHttpClient("ExternalApi",
      client => client.BaseAddress = new Uri("https://localhost:7277"))
      .AddHttpMessageHandler<TokenHandler>();
```

You can supply the HTTP client base address from [configuration](xref:blazor/fundamentals/configuration) with `builder.Configuration["{CONFIGURATION KEY}"]`, where the `{CONFIGURATION KEY}` placeholder is the configuration key:

```csharp
new Uri(builder.Configuration["ExternalApiUri"] ?? throw new IOException("No URI!"))
```

In `appsettings.json`, specify the `ExternalApiUri`. The following example sets the value to the localhost address of the external web API to `https://localhost:7277`:

```json
"ExternalApiUri": "https://localhost:7277"
```

At this point, an <xref:System.Net.Http.HttpClient> created by a component can make secure web API requests. In the following example, the `{REQUEST URI}` is the relative request URI, and the `{HTTP CLIENT NAME}` placeholder is the name of the <xref:System.Net.Http.HttpClient>:

```csharp
using var request = new HttpRequestMessage(HttpMethod.Get, "{REQUEST URI}");
var client = ClientFactory.CreateClient("{HTTP CLIENT NAME}");
using var response = await client.SendAsync(request);
```

Example:

View on GitHub (pinned to c67a80103a)

Solutions

  1. Add "ExternalApiUri": "https://localhost:7277" (or production URL) to appsettings.json or the per-environment appsettings.
  2. Set the ExternalApiUri environment variable in Production.
  3. Set a user-secret in Development: dotnet user-secrets set "ExternalApiUri" "https://localhost:7277".
  4. Validate configuration keys at startup to surface missing values with a precise message.

Example fix

// before
new Uri(builder.Configuration["ExternalApiUri"] ?? throw new IOException("No URI!"))

// after — validated config with clear guidance
var externalApiUri = builder.Configuration["ExternalApiUri"]
    ?? throw new InvalidOperationException(
        "Configuration key 'ExternalApiUri' is missing. " +
        "Set it in appsettings.json, user-secrets, or an environment variable.");
client.BaseAddress = new Uri(externalApiUri);
Defensive patterns

Strategy: validation

Validate before calling

var uri = builder.Configuration["ExternalApiUri"];
if (!Uri.TryCreate(uri, UriKind.Absolute, out _)) {
    throw new InvalidOperationException("Configure a valid 'ExternalApiUri'.");
}

Type guard

static bool IsValidUri(string? s) => Uri.TryCreate(s, UriKind.Absolute, out _);

Try / catch

try { /* startup */ }
catch (IOException ex) when (ex.Message.Contains("No URI"))
{
    host.LogCritical("ExternalApiUri not configured.");
    throw;
}

Prevention

When it happens

Trigger: ExternalApiUri configuration value is absent from appsettings.json, environment variables, or user secrets when AddHttpClient's configuration delegate executes.

Common situations: Missing ExternalApiUri in a deployment environment; key renamed without updating code; local dev without user-secrets; CI/test environment without the variable set.

Related errors


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