dotnet/wpf · error · ArgumentException
SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriRemote"…
Error message
SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriRemote", "OriginalString")
What it means
GetRemoteStream validates that the Uri's OriginalString is not null before resolving a site-of-origin resource. A Uri can be constructed such that OriginalString is null (e.g. default(Uri) survived the null check via serialization or UriKind.RelativeOrRelative tricks), and WPF treats that as an invalid argument. This guards the subsequent resolution logic from a malformed Uri instance.
Solutions
- Ensure the Uri is constructed via a normal Uri constructor with a non-null string before passing it
- Check uriRemote?.OriginalString != null before calling GetRemoteStream
- Re-create the Uri from its string form if it came from deserialization
- If the value may be absent, skip the call or use a relative Uri with UriKind.Relative
Example fix
// before
Application.GetRemoteStream(maybeUri);
// after
if (maybeUri?.OriginalString != null)
Application.GetRemoteStream(maybeUri); Defensive patterns
Strategy: type-guard
Validate before calling
bool hasString(Uri u) => u?.OriginalString != null;
Type guard
bool HasOriginalString(Uri u) => u is Uri uri && uri.OriginalString is string s;
Try / catch
try { Application.GetRemoteStream(uri); } catch (ArgumentException ex) { /* rebuild uri from its string form */ } Prevention
- Construct Uris only via standard constructors
- Re-create Uris after deserialization
- Treat deserialized Uri instances as suspect
When it happens
Trigger: Calling Application.GetRemoteStream with a Uri instance whose OriginalString is null — typically a Uri built through unusual paths (deserialization, default struct) rather than a normal constructor, since the constructor normally throws on null input.
Common situations: Uris round-tripped through serialization/formatters that skipped validation; reflection-created Uri instances; defensive check rarely hit because ArgumentNullException fires first on true nulls.
Related errors
- SR.AbsoluteUriOnly
- SR.Effect_SourceUriMustBeFileOrPack
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriResource"…
- SR.NonPackAppAbsoluteUriNotAllowed
- SR.NonPackSooAbsoluteUriNotAllowed
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/0bc9d06246ac0cdd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs:640
/// <summary>
/// Get PackagePart for a uri, the uri maps to a file which comes from the place
/// where the application was originally deployed.
///
/// The accepted uri could be relative uri such as "foo.jpg"
///
/// or pack Uri, "pack://siteoforigin:,,,/foo.jpg"
///
/// </summary>
/// <param name="uriRemote">the uri maps to the resource</param>
/// <returns>PackagePart or null</returns>
public static StreamResourceInfo GetRemoteStream(Uri uriRemote)
{
SiteOfOriginPart sooPart = null;
ArgumentNullException.ThrowIfNull(uriRemote);
if (uriRemote.OriginalString == null)
throw new ArgumentException(SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriRemote", "OriginalString"));
if (uriRemote.IsAbsoluteUri)
{
if (!BaseUriHelper.SiteOfOriginBaseUri.IsBaseOf(uriRemote))
{
throw new ArgumentException(SR.NonPackSooAbsoluteUriNotAllowed);
}
}
Uri resolvedUri = BindUriHelper.GetResolvedUri(BaseUriHelper.SiteOfOriginBaseUri, uriRemote);
Uri packageUri = PackUriHelper.GetPackageUri(resolvedUri);
Uri partUri = PackUriHelper.GetPartUri(resolvedUri);
//
// SiteOfOriginContainer must have been added into the package cache, the code should just
// take use of that SiteOfOriginContainer instance, instead of creating a new instance here.
//View on GitHub (pinned to 81131a70a4)