dotnet/wpf · error · ArgumentException

SR.NonPackSooAbsoluteUriNotAllowed

Error message

SR.NonPackSooAbsoluteUriNotAllowed

What it means

GetRemoteStream loads files from the site of origin — the location the application was deployed from. Absolute URIs passed to it must fall under the pack siteoforigin base (pack://siteoforigin:,,,). Any other absolute URI (http://, file://, pack://application:,,,) is rejected with ArgumentException because the API cannot treat it as a site-of-origin resource.

Solutions

  1. Use a pack://siteoforigin:,,,/filename URI or a relative Uri for deployed loose files
  2. For compiled-in resources, call GetContentStream with pack://application:,,, instead
  3. For arbitrary URLs, use HttpClient/WebClient rather than GetRemoteStream
  4. Check BaseUriHelper.SiteOfOriginBaseUri.IsBaseOf(uri) before calling to validate

Example fix

// before
var s = Application.GetRemoteStream(new Uri("http://cdn.example.com/config.xml"));
// after
var s = Application.GetRemoteStream(new Uri("pack://siteoforigin:,,,/config.xml"));
Defensive patterns

Strategy: validation

Validate before calling

bool isSooUri(Uri u) => !u.IsAbsoluteUri || BaseUriHelper.SiteOfOriginBaseUri.IsBaseOf(u);

Type guard

bool IsValidRemoteUri(Uri u) => u is not null && (!u.IsAbsoluteUri || (u.Scheme == Uri.UriSchemePack && u.AbsoluteUri.StartsWith("pack://siteoforigin")));

Try / catch

try { var s = Application.GetRemoteStream(uri); } catch (ArgumentException ex) { /* use pack://siteoforigin or HttpClient */ }

Prevention

When it happens

Trigger: Calling Application.GetRemoteStream with an absolute Uri not based on pack://siteoforigin:,,, — e.g. new Uri("http://server/file.jpg"), new Uri("file:///C:/x.jpg"), or a pack://application:,,, URI (which belongs to GetContentStream).

Common situations: Mixing up GetContentStream (pack application) and GetRemoteStream (pack siteoforigin); passing web URLs expecting the API to download files; ClickOnce apps where loose files resolve via siteoforigin but the code passes a file:// path.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/d2c6054b000f4e8c. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs:646

        /// 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.
            //
            SiteOfOriginContainer sooContainer = (SiteOfOriginContainer)GetResourcePackage(packageUri);

            // the SiteOfOriginContainer is shared across threads;  synchronize access to it
            // using the same lock object as other uses (PackWebResponse+CachedResponse.GetResponseStream)
            lock (sooContainer)
            {

View on GitHub (pinned to 81131a70a4)