dotnet/wpf · error · ArgumentException
The URI must be absolute.
Error message
The URI must be absolute.
What it means
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.
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.
Example fix
// before
var uri = new Uri("images/logo.png", UriKind.Relative);
Verify.UriIsAbsolute(uri, nameof(uri));
// after
var uri = new Uri(new Uri("pack://application:,,,/MyApp;component/"), "images/logo.png");
Verify.UriIsAbsolute(uri, nameof(uri)); Defensive patterns
Strategy: validation
Validate before calling
if (uri == null || !uri.IsAbsoluteUri)
throw new ArgumentException("A absolute URI is required", nameof(uri));
Verify.UriIsAbsolute(uri, nameof(uri)); Type guard
static bool IsAbsoluteUri(Uri uri) => uri is not null && uri.IsAbsoluteUri;
Try / catch
try {
Verify.UriIsAbsolute(uri, nameof(uri));
} catch (ArgumentException ex) when (ex.ParamName == nameof(uri)) {
uri = new Uri(new Uri(AppContext.BaseDirectory), originalRelative);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- SR.AbsoluteUriNotAllowed
- SR.Format(SR.ArgumentPropertyMustNotBeNull,"resourceLocator"…
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriContent"…
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriResource"…
- SR.UriNotAbsolute
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/553ff90e40ce1099.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs:220
// Two nulls are considered equal, regardless of type semantics.
if (null == actual || actual.Equals(notExpected))
{
throw new ArgumentException(message, parameterName);
}
}
else if (notExpected.Equals(actual))
{
throw new ArgumentException(message, parameterName);
}
}
[DebuggerStepThrough]
public static void UriIsAbsolute(Uri uri, string parameterName)
{
Verify.IsNotNull(uri, parameterName);
if (!uri.IsAbsoluteUri)
{
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>
[DebuggerStepThrough]
public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)
{
if (value < lowerBoundInclusive || value >= upperBoundExclusive)
{
throw new ArgumentException(string.Create(CultureInfo.InvariantCulture, $"The integer value must be bounded with [{lowerBoundInclusive}, {upperBoundExclusive})"), parameterName);
}
}
View on GitHub (pinned to 81131a70a4)