{"record":{"id":"efe03cf5347435a9","repo":"git-ecosystem/git-credential-manager","slug":"argument-must-be-an-absolute-uri","errorCode":null,"errorMessage":"Argument must be an absolute URI.","messagePattern":"Argument must be an absolute URI\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Core/EnsureArgument.cs","lineNumber":41,"sourceCode":"        }\n\n        public static void NotNullOrWhiteSpace(string arg, string name)\n        {\n            NotNull(arg, name);\n\n            if (string.IsNullOrWhiteSpace(arg))\n            {\n                throw new ArgumentException(\"Argument cannot be empty or white space.\", name);\n            }\n        }\n\n        public static void AbsoluteUri(Uri arg, string name)\n        {\n            NotNull(arg, name);\n\n            if (!arg.IsAbsoluteUri)\n            {\n                throw new ArgumentException(\"Argument must be an absolute URI.\", name);\n            }\n        }\n\n        public static void PositiveOrZero(int arg, string name)\n        {\n            if (arg < 0)\n            {\n                throw new ArgumentOutOfRangeException(name, \"Argument must be positive or zero (non-negative).\");\n            }\n        }\n\n        public static void Positive(int arg, string name)\n        {\n            if (arg <= 0)\n            {\n                throw new ArgumentOutOfRangeException(name, \"Argument must be positive.\");\n            }\n        }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/EnsureArgument.cs#L23-L59","documentation":"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.","triggerScenarios":"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://\".","commonSituations":"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.","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"],"exampleFix":"// before\nvar uri = new Uri(config.Endpoint); // relative: \"api/items\"\nEnsureArgument.AbsoluteUri(uri, nameof(uri));\n// after\nif (!Uri.TryCreate(config.Endpoint, UriKind.Absolute, out var uri))\n    throw new InvalidOperationException($\"Endpoint '{config.Endpoint}' is not an absolute URI\");\nEnsureArgument.AbsoluteUri(uri, nameof(uri));","handlingStrategy":"validation","validationCode":"if (!Uri.TryCreate(raw, UriKind.Absolute, out var uri))\n    throw new InvalidOperationException($\"'{raw}' is not an absolute URI (scheme required)\");","typeGuard":"static bool IsAbsoluteUri(string? raw) => Uri.TryCreate(raw, UriKind.Absolute, out _);","tryCatchPattern":"try { EnsureArgument.AbsoluteUri(endpoint, nameof(endpoint)); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(endpoint))\n{\n    throw new ConfigurationErrorsException($\"Endpoint must be an absolute URI, got '{endpoint}'\", ex);\n}","preventionTips":["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"],"tags":["argument-validation","uri","csharp"],"backgroundTag":"invalid-url-format","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}