dotnet/wpf · error · ArgumentException
SR.Format(SR.ArgumentPropertyMustNotBeNull,"resourceLocator"…
Error message
SR.Format(SR.ArgumentPropertyMustNotBeNull,"resourceLocator", "OriginalString")
What it means
Application.LoadComponent(Object, Uri) validates the resourceLocator Uri before loading XAML. If the Uri's OriginalString is null it throws ArgumentException describing that resourceLocator.OriginalString must not be null. A Uri object can wrap a null string only via unsafe construction, so this is a defensive argument validation.
Solutions
- Ensure the Uri is created from a non-null string, e.g. new Uri("MyPage.xaml", UriKind.Relative)
- Guard the caller: skip LoadComponent when uri == null || uri.OriginalString == null
- Fix the source of the null OriginalString (deserialization/property initialization)
Example fix
// before
Uri uri = GetUriSomehow(); // OriginalString == null
Application.LoadComponent(page, uri);
// after
var uri = new Uri("MyPage.xaml", UriKind.Relative);
Application.LoadComponent(page, uri); Defensive patterns
Strategy: validation
Validate before calling
if (uri == null || uri.OriginalString == null)
throw new ArgumentException("resourceLocator must have a non-null OriginalString");
Application.LoadComponent(component, uri); Type guard
static bool IsValidLocator(Uri u) => u?.OriginalString != null;
Try / catch
try { Application.LoadComponent(component, uri); }
catch (ArgumentException ex) { Log(ex); LoadFallbackComponent(); } Prevention
- Always construct Uri from literal/validated non-null strings
- Validate Uri arguments at component boundaries before calling LoadComponent
- Never pass Uris that came from unchecked deserialization
When it happens
Trigger: Passing a Uri instance whose OriginalString is null into LoadComponent(Object component, Uri resourceLocator).
Common situations: Uri created through deserialization or interop with a null backing string; a default(Uri)-like flow assigning an uninitialized value that is later boxed into a property; binding a URI property that was never initialized.
Related errors
- SR.AbsoluteUriNotAllowed
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriContent"…
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriResource"…
- SR.UriNotAbsolute
- The URI must be absolute.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/392d8092f0789f16.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs:352
{
bool canCache;
return resources.FetchResource(resourceKey, allowDeferredResourceReference, mustReturnDeferredResourceReference, out canCache);
}
}
/// <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
};
View on GitHub (pinned to 81131a70a4)