dotnet/maui · error · ArgumentException
The URI must be absolute.
Error message
The URI must be absolute.
What it means
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.
Source
Thrown at src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs:241
throw new ArgumentException(message, parameterName);
}
}
else if (notExpected.Equals(actual))
{
Assert.Fail();
throw new ArgumentException(message, parameterName);
}
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void UriIsAbsolute(Uri uri, string parameterName)
{
Verify.IsNotNull(uri, parameterName);
if (!uri.IsAbsoluteUri)
{
Assert.Fail();
throw new ArgumentException("The URI must be absolute.", parameterName);
}
}
/// <summary>
/// Verifies that the specified value is within the expected range. The assertion fails if it isn't.
/// </summary>
/// <param name="lowerBoundInclusive">The lower bound inclusive value.</param>
/// <param name="value">The value to verify.</param>
/// <param name="upperBoundExclusive">The upper bound exclusive value.</param>
/// <param name="parameterName">The name of the parameter that caused the current exception.</param>
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)
{
if (value < lowerBoundInclusive || value >= upperBoundExclusive)
{
Assert.Fail();
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The integer value must be bounded with [{0}, {1})", lowerBoundInclusive, upperBoundExclusive), parameterName);View on GitHub (pinned to f377ff1c5e)
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.
Example fix
// before
var uri = new Uri("/assets/icon.png", UriKind.Relative);
LoadResource(uri);
// after
var uri = new Uri(baseUri, "/assets/icon.png");
// or
var uri = new Uri("pack://application:,,,/assets/icon.png", UriKind.Absolute);
LoadResource(uri); Defensive patterns
Strategy: validation
Validate before calling
// Pre-check: Uri must be absolute
if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}
if (!uri.IsAbsoluteUri)
{
// combine with a base or reject
uri = new Uri(baseUri, uri);
}
SomeApi(uri); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The parameter cannot be either null or empty.
- The parameter cannot be either null or empty or consist only
- The parameter must not be the default value.
- The parameter must be null.
- The integer value must be bounded with [{0}, {1})
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/dc02e344b8ce081c.
Report an issue: GitHub.