git-ecosystem/git-credential-manager · error · ArgumentException
Argument must be an absolute URI.
Error message
Argument must be an absolute URI.
What it means
This ArgumentException is thrown by EnsureArgument.AbsoluteUri when a Uri argument is not an absolute URI (i.e., it is relative, such as "/api/items" or lacks a scheme). The library requires absolute URIs so it can resolve endpoints without a base address. The parameter name is included in the exception.
Solutions
- Ensure the Uri has a scheme and host (e.g., prefix "https://" if missing) before passing it
- Use Uri.TryCreate(value, UriKind.Absolute, out var uri) to validate the value at parse time
- Fix the configuration or caller supplying a relative path; combine a relative path with a base Uri via new Uri(baseUri, relative)
- Verify with uri.IsAbsoluteUri before calling the API
Example fix
// before
var uri = new Uri(config.Endpoint); // relative: "api/items"
EnsureArgument.AbsoluteUri(uri, nameof(uri));
// after
if (!Uri.TryCreate(config.Endpoint, UriKind.Absolute, out var uri))
throw new InvalidOperationException($"Endpoint '{config.Endpoint}' is not an absolute URI");
EnsureArgument.AbsoluteUri(uri, nameof(uri)); Defensive patterns
Strategy: validation
Validate before calling
if (!Uri.TryCreate(raw, UriKind.Absolute, out var uri))
throw new InvalidOperationException($"'{raw}' is not an absolute URI (scheme required)"); Type guard
static bool IsAbsoluteUri(string? raw) => Uri.TryCreate(raw, UriKind.Absolute, out _);
Try / catch
try { EnsureArgument.AbsoluteUri(endpoint, nameof(endpoint)); }
catch (ArgumentException ex) when (ex.ParamName == nameof(endpoint))
{
throw new ConfigurationErrorsException($"Endpoint must be an absolute URI, got '{endpoint}'", ex);
} Prevention
- Always include scheme (https://) in configured endpoints
- Validate URIs with Uri.TryCreate(UriKind.Absolute) at parse time
- Use Uri.Combine/new Uri(base, relative) instead of string concatenation for paths
- Add a startup config check that all endpoint settings are absolute URIs
When it happens
Trigger: Calling EnsureArgument.AbsoluteUri(arg, name) when arg is a relative Uri such as new Uri("api/items", UriKind.Relative) or new Uri("/path"), or when a base-URI-dependent Uri was constructed without a scheme like "https://".
Common situations: Building a client with a config value that omitted the scheme ("myhost:8080" instead of "https://myhost:8080"); concatenating path fragments into a Uri; a config migration dropping the scheme.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- Not a valid URI
- Must specify at least one AuthenticationModes
- Argument cannot be empty or white space.
- Argument must be positive or zero (non-negative).
- Argument must be positive.
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/efe03cf5347435a9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Core/EnsureArgument.cs:41
}
public static void NotNullOrWhiteSpace(string arg, string name)
{
NotNull(arg, name);
if (string.IsNullOrWhiteSpace(arg))
{
throw new ArgumentException("Argument cannot be empty or white space.", name);
}
}
public static void AbsoluteUri(Uri arg, string name)
{
NotNull(arg, name);
if (!arg.IsAbsoluteUri)
{
throw new ArgumentException("Argument must be an absolute URI.", name);
}
}
public static void PositiveOrZero(int arg, string name)
{
if (arg < 0)
{
throw new ArgumentOutOfRangeException(name, "Argument must be positive or zero (non-negative).");
}
}
public static void Positive(int arg, string name)
{
if (arg <= 0)
{
throw new ArgumentOutOfRangeException(name, "Argument must be positive.");
}
}View on GitHub (pinned to e8ce762cd0)