dotnet/wpf · error · ArgumentException
SR.AbsoluteUriNotAllowed
Error message
SR.AbsoluteUriNotAllowed
What it means
Application.LoadComponent(Object, Uri) only accepts relative Uris, because it resolves them against the application's pack base URI (PackAppBaseUri). An absolute Uri throws ArgumentException with SR.AbsoluteUriNotAllowed. The caller must pass a relative resource path such as "MyPage.xaml".
Solutions
- Pass a relative Uri: new Uri("MyPage.xaml", UriKind.Relative)
- Convert an existing absolute pack Uri to relative with BaseUriHelper or by stripping the pack base: BaseUriHelper.PackAppBaseUri.MakeRelativeUri(absUri)
- Use Navigation APIs (frame.Navigate) for absolute Uris instead of LoadComponent
Example fix
// before
var uri = new Uri("pack://application:,,,/Views/MyPage.xaml");
Application.LoadComponent(page, uri); // ArgumentException
// after
var uri = new Uri("Views/MyPage.xaml", UriKind.Relative);
Application.LoadComponent(page, uri); Defensive patterns
Strategy: validation
Validate before calling
if (uri.IsAbsoluteUri)
uri = BaseUriHelper.PackAppBaseUri.MakeRelativeUri(uri);
Application.LoadComponent(component, uri); Type guard
static bool IsRelativeLocator(Uri u) => u != null && !u.IsAbsoluteUri;
Try / catch
try { Application.LoadComponent(component, uri); }
catch (ArgumentException) { uri = new Uri(Relativize(uri), UriKind.Relative); Application.LoadComponent(component, uri); } Prevention
- Use new Uri(path, UriKind.Relative) for all LoadComponent calls
- Convert absolute pack Uris with MakeRelativeUri against PackAppBaseUri
- Use Frame.Navigate for scenarios where absolute Uris are expected
When it happens
Trigger: Calling LoadComponent(component, new Uri("pack://application:,,,/MyPage.xaml")) or any other absolute Uri (file://, http://, absolute pack://).
Common situations: Storing full pack URIs in configuration and passing them straight to LoadComponent; converting a NavigationWindow's absolute source Uri into a LoadComponent call; mixing up LoadComponent with NavigationService which does accept absolute Uris.
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
- assembly
- SR.CollectionCannotContainNulls
- SR.Format(SR.ArgumentPropertyMustNotBeNull,"resourceLocator"…
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriContent"…
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriResource"…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/699585f40d15a863.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs:355
}
}
/// <summary>
/// Create logic tree from given resource Locator, and associate this
/// tree with the given component.
/// </summary>
/// <param name="component">Root Element</param>
/// <param name="resourceLocator">Resource Locator</param>
public static void LoadComponent(Object component, Uri resourceLocator)
{
ArgumentNullException.ThrowIfNull(component);
ArgumentNullException.ThrowIfNull(resourceLocator);
if (resourceLocator.OriginalString == null)
throw new ArgumentException(SR.Format(SR.ArgumentPropertyMustNotBeNull,"resourceLocator", "OriginalString"));
if (resourceLocator.IsAbsoluteUri)
throw new ArgumentException(SR.AbsoluteUriNotAllowed);
// Passed a relative Uri here.
// needs to resolve it to Pack://Application.
//..\..\ in the relative Uri will get stripped when creating the new Uri and resolving to the
//PackAppBaseUri, i.e. only relative Uri within the appbase are created here
Uri currentUri = new Uri(BaseUriHelper.PackAppBaseUri, resourceLocator);
//
// Generate the ParserContext from packUri
//
ParserContext pc = new ParserContext
{
BaseUri = currentUri
};
bool bCloseStream = true; // Whether or not to close the stream after LoadBaml is done.
Stream stream = null; // stream could be extracted from the manifest resource or cached in theView on GitHub (pinned to 81131a70a4)