dotnet/wpf · error · ApplicationException

SR.PageContentNotFound

Error message

SR.PageContentNotFound

What it means

GetPageStream throws ApplicationException with SR.PageContentNotFound when the web request created for the page's Source URI returns a null stream, meaning the referenced page content could not be retrieved from the package/URI.

Solutions

  1. Verify the page part exists at the URI the PageContent.Source resolves to inside the package
  2. Regenerate or repair the XPS package so relationship targets match actual parts
  3. Check URI casing and package-relative path correctness (XPS URIs are case-sensitive)

Example fix

// before
// Source="/Documents/Pages/Page1.fpage" but part is "/Documents/pages/Page1.fpage"
// after
// fix Source to match the actual part path exactly
pageContent.Source = new Uri("/Documents/pages/Page1.fpage", UriKind.Relative);
Defensive patterns

Strategy: try-catch

Validate before calling

var uri = ((IUriContext)pageContent).BaseUri; // verify Source resolves within package before requesting

Try / catch

try { var s = GetPageStream(uri); } catch (ApplicationException) { /* page part missing: repair package or use fallback */ }

Prevention

When it happens

Trigger: Calling GetPageStream (or IPageContent_REMOTE GetPageAsync paths) for a PageContent whose Source URI points to a non-existent or unreachable page part after EnforcePackageRelativeUri validation passed.

Common situations: Broken or renamed .fpage parts inside an XPS package; missing relationship targets; manually edited ZIP package where page files were removed or paths mis-cased.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs:374

            return false;
        }

        internal Stream GetPageStream()
        {
            Uri uriToLoad = _ResolveUri();
            Stream pageStream = null;

            if (uriToLoad != null)
            {
                // Package-boundary guard. Reject any uriToLoad that is not
                // an absolute pack:// reference inside the same package as
                // the parent (this PageContent's BaseUri). This enforces
                // XPS specification containment requirements.
                XpsLoadingContext.EnforcePackageRelativeUri(((IUriContext)this).BaseUri, uriToLoad);
                pageStream = WpfWebRequestHelper.CreateRequestAndGetResponseStream(uriToLoad);
                if (pageStream == null)
                {
                    throw new ApplicationException(SR.PageContentNotFound);
                }
            }

            return pageStream;
        }
        #endregion Internal Methods


        //--------------------------------------------------------------------
        //
        // Internal Properties
        //
        //---------------------------------------------------------------------

        #region Internal Properties
        // return nested PageStream
        internal FixedPage PageStream
        {

View on GitHub (pinned to 81131a70a4)