{"record":{"id":"553ff90e40ce1099","repo":"dotnet/wpf","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/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs","lineNumber":220,"sourceCode":"                // Two nulls are considered equal, regardless of type semantics.\n                if (null == actual || 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        public static void UriIsAbsolute(Uri uri, string parameterName)\n        {\n            Verify.IsNotNull(uri, parameterName);\n            if (!uri.IsAbsoluteUri)\n            {\n                throw new ArgumentException(\"The URI must be absolute.\", parameterName);\n            }\n        }\n\n        /// <summary>\n        /// Verifies that the specified value is within the expected range.  The assertion fails if it isn't.\n        /// </summary>\n        /// <param name=\"lowerBoundInclusive\">The lower bound inclusive value.</param>\n        /// <param name=\"value\">The value to verify.</param>\n        /// <param name=\"upperBoundExclusive\">The upper bound exclusive value.</param>      \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.Create(CultureInfo.InvariantCulture, $\"The integer value must be bounded with [{lowerBoundInclusive}, {upperBoundExclusive})\"), parameterName);\n            }\n        }\n        ","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs#L202-L238","documentation":"Verify.UriIsAbsolute first asserts the Uri is non-null, then asserts uri.IsAbsoluteUri is true, throwing ArgumentException('The URI must be absolute.', parameterName) for relative URIs like 'page.xaml' or '/path'. Many WPF/interop APIs need scheme+host information that only absolute URIs carry.","triggerScenarios":"Calling Verify.UriIsAbsolute(uri, parameterName) (or APIs that use it, e.g. navigation/pack URI helpers) with a relative Uri such as new Uri(\"images/pic.png\", UriKind.Relative) or a relative string parsed via Uri.TryCreate with UriKind.RelativeOrRelative-only.","commonSituations":"Config/app settings storing relative paths; user-supplied URLs lacking a scheme; code that builds Uri without UriKind.Absolute; switching environments where a base URL was dropped.","solutions":["Ensure the Uri is created with UriKind.Absolute and includes scheme (http://, pack://application:,,,/, file:///).","Resolve relative URIs against a known base before the call: new Uri(new Uri(baseUri), relative).","For WPF resources, use pack URIs (pack://application:,,,/Assembly;component/path) to make them absolute.","Validate with uri.IsAbsoluteUri yourself first and give the user a clear error message."],"exampleFix":"// before\nvar uri = new Uri(\"images/logo.png\", UriKind.Relative);\nVerify.UriIsAbsolute(uri, nameof(uri));\n// after\nvar uri = new Uri(new Uri(\"pack://application:,,,/MyApp;component/\"), \"images/logo.png\");\nVerify.UriIsAbsolute(uri, nameof(uri));","handlingStrategy":"validation","validationCode":"if (uri == null || !uri.IsAbsoluteUri)\n    throw new ArgumentException(\"A absolute URI is required\", nameof(uri));\nVerify.UriIsAbsolute(uri, nameof(uri));","typeGuard":"static bool IsAbsoluteUri(Uri uri) => uri is not null && uri.IsAbsoluteUri;","tryCatchPattern":"try {\n    Verify.UriIsAbsolute(uri, nameof(uri));\n} catch (ArgumentException ex) when (ex.ParamName == nameof(uri)) {\n    uri = new Uri(new Uri(AppContext.BaseDirectory), originalRelative);\n}","preventionTips":["Always create Uri with UriKind.Absolute when an absolute URI is required.","Resolve relative paths against an explicit base URI early.","Use pack:// URIs for WPF resource references.","Validate URIs from config/user input at load time."],"tags":["wpf","uri","argument-validation","invalid-url"],"backgroundTag":"invalid-url-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}