{"record":{"id":"dc02e344b8ce081c","repo":"dotnet/maui","slug":"the-uri-must-be-absolute","errorCode":null,"errorMessage":"The URI must be absolute.","messagePattern":"The URI must be absolute\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":241,"sourceCode":"\t\t\t\t\tthrow new ArgumentException(message, parameterName);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (notExpected.Equals(actual))\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(message, parameterName);\n\t\t\t}\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void UriIsAbsolute(Uri uri, string parameterName)\n\t\t{\n\t\t\tVerify.IsNotNull(uri, parameterName);\n\t\t\tif (!uri.IsAbsoluteUri)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(\"The URI must be absolute.\", parameterName);\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Verifies that the specified value is within the expected range.  The assertion fails if it isn't.\n\t\t/// </summary>\n\t\t/// <param name=\"lowerBoundInclusive\">The lower bound inclusive value.</param>\n\t\t/// <param name=\"value\">The value to verify.</param>\n\t\t/// <param name=\"upperBoundExclusive\">The upper bound exclusive value.</param>\n\t\t/// <param name=\"parameterName\">The name of the parameter that caused the current exception.</param>\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)\n\t\t{\n\t\t\tif (value < lowerBoundInclusive || value >= upperBoundExclusive)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(string.Format(CultureInfo.InvariantCulture, \"The integer value must be bounded with [{0}, {1})\", lowerBoundInclusive, upperBoundExclusive), parameterName);","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs#L223-L259","documentation":"Verify.UriIsAbsolute throws ArgumentException when the supplied Uri is relative (uri.IsAbsoluteUri is false). The helper first null-checks the Uri via Verify.IsNotNull, then asserts absoluteness. It is used to guard APIs that require scheme, host, and absolute path information that only absolute URIs carry.","triggerScenarios":"Calling a method guarded by Verify.UriIsAbsolute(uri, paramName) with a relative Uri such as new Uri(\"/path/to/resource\", UriKind.Relative). The IsAbsoluteUri check returns false and the guard fires.","commonSituations":"XAML pack URIs that are relative; user-entered URLs missing the scheme; Uri constructed from a path without a base; APIs that build Uris from fragments and forget to combine with a base URI.","solutions":["Construct the Uri as absolute: new Uri(baseUri, relativeUri) or specify UriKind.Absolute.","Validate uri.IsAbsoluteUri before calling the guarded API.","Ensure the scheme is present (e.g. \"http://\", \"pack://application:,,,\") when constructing the Uri."],"exampleFix":"// before\nvar uri = new Uri(\"/assets/icon.png\", UriKind.Relative);\nLoadResource(uri);\n\n// after\nvar uri = new Uri(baseUri, \"/assets/icon.png\");\n// or\nvar uri = new Uri(\"pack://application:,,,/assets/icon.png\", UriKind.Absolute);\nLoadResource(uri);","handlingStrategy":"validation","validationCode":"// Pre-check: Uri must be absolute\nif (uri == null)\n{\n    throw new ArgumentNullException(nameof(uri));\n}\nif (!uri.IsAbsoluteUri)\n{\n    // combine with a base or reject\n    uri = new Uri(baseUri, uri);\n}\nSomeApi(uri);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include the scheme (http://, pack://, file://) when constructing Uris for guarded APIs.","Combine relative Uris with a known base before passing them onward.","Check uri.IsAbsoluteUri in debug assertions to catch relative Uris early."],"tags":["validation","argument","uri","relative-uri","verify"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}