| title | HCR087 — BaseAddress should end with a trailing slash |
|---|---|
| description | A BaseAddress whose path does not end with '/' causes relative request URIs to resolve against the parent segment, silently dropping the last path component. |
HttpClient.BaseAddress with a non-root path must end with /.
Relative request URIs resolve against BaseAddress using RFC 3986 rules: the last path segment of the base is treated as a resource name and replaced. BaseAddress = "https://api.example.com/v1" combined with GetAsync("users") produces https://api.example.com/users, not https://api.example.com/v1/users — the v1 segment is silently dropped and every relative request hits the wrong endpoint.
client.BaseAddress = new Uri("https://api.example.com/v1");
var response = await client.GetAsync("users"); // GET https://api.example.com/usersTerminate the base path with /:
client.BaseAddress = new Uri("https://api.example.com/v1/");
var response = await client.GetAsync("users"); // GET https://api.example.com/v1/usersThe implementation reports BaseAddress assignments on a System.Net.Http.HttpClient receiver when the value is a constant absolute URI (a string literal or new Uri("literal")) whose path is non-root and does not end with /. Root-only URIs (https://api.example.com), URIs already ending in /, non-constant values, and custom BaseAddress lookalikes are skipped.
Suppress only when the trailing-segment drop is intended — for example when every request URI is absolute or begins with /. Prefer adding the slash; it is almost always the intended shape.