{"record":{"id":"9979ea4f07bfe0c7","repo":"HandyOrg/HandyControl","slug":"the-uri-must-be-absolute","errorCode":null,"errorMessage":"The URI must be absolute.","messagePattern":"The URI must be absolute\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":170,"sourceCode":"            if (actual == null || actual.Equals(notExpected))\n            {\n                throw new ArgumentException(message, parameterName);\n            }\n        }\n        else if (notExpected.Equals(actual))\n        {\n            throw new ArgumentException(message, parameterName);\n        }\n    }\n\n    [DebuggerStepThrough]\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    public static void UriIsAbsolute(Uri uri, string parameterName)\n    {\n        Verify.IsNotNull<Uri>(uri, parameterName);\n        if (!uri.IsAbsoluteUri)\n        {\n            throw new ArgumentException(\"The URI must be absolute.\", parameterName);\n        }\n    }\n\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    [DebuggerStepThrough]\n    public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)\n    {\n        if (value < lowerBoundInclusive || value >= upperBoundExclusive)\n        {\n            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, \"The integer value must be bounded with [{0}, {1})\", new object[]\n            {\n                lowerBoundInclusive,\n                upperBoundExclusive\n            }), parameterName);\n        }\n    }\n\n    [DebuggerStepThrough]","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs#L152-L188","documentation":"Verify.UriIsAbsolute is a debug-style argument validator in the Microsoft.Windows.Shell helper library. It asserts that the Uri parameter passed to an API is an absolute URI (has a scheme such as 'pack:' or 'http:'). It first checks for null, then throws ArgumentException when Uri.IsAbsoluteUri is false.","triggerScenarios":"Calling any API in the Microsoft.Windows.Shell/Standard utility layer that routes through Verify.UriIsAbsolute with a relative Uri (e.g. new Uri(\"images/foo.png\", UriKind.Relative)) or a null Uri.","commonSituations":"Developers construct URIs from strings that lack a scheme, or use UriKind.Relative by mistake when an absolute URI (usually a pack:// application resource URI) is expected.","solutions":["Ensure the Uri is created with UriKind.Absolute and includes a scheme, e.g. new Uri(\"pack://application:,,,/Images/foo.png\")","If starting from a relative path, resolve it against a base Uri: new Uri(baseUri, relativePath)","Null-check and validate uri.IsAbsoluteUri before calling the library API"],"exampleFix":"// before\nvar uri = new Uri(\"images/foo.png\", UriKind.Relative);\nChromeApi.SetIcon(uri);\n// after\nvar uri = new Uri(\"pack://application:,,,/images/foo.png\", UriKind.Absolute);\nChromeApi.SetIcon(uri);","handlingStrategy":"validation","validationCode":"if (uri == null || !uri.IsAbsoluteUri) throw new ArgumentException(\"An absolute URI is required\", nameof(uri));","typeGuard":"bool IsAbsolute(Uri u) => u != null && u.IsAbsoluteUri;","tryCatchPattern":"try { api.Call(uri); } catch (ArgumentException ex) when (ex.Message.Contains(\"absolute\")) { /* handle relative URI case */ }","preventionTips":["Always construct Uris with UriKind.Absolute when passing to shell APIs","Use pack://application:,,,/ URIs for embedded WPF resources","Null-check Uris before use"],"tags":["argument-validation","uri","wpf"],"backgroundTag":"invalid-url-format","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}