dotnet/wpf · error · ApplicationException

SR.PageContentUnsupportedMimeType

Error message

SR.PageContentUnsupportedMimeType

What it means

_LoadPageImpl throws ApplicationException with SR.PageContentUnsupportedMimeType when the loaded page stream's content type is neither XAML nor BAML (per MimeTypeMapper checks). PageContent only knows how to parse XAML/BAML into a FixedPage.

Solutions

  1. Ensure the page part is XAML FixedPage content with the correct XPS content type
  2. Fix the part's Content-Type metadata in the package ([Content_Types].xml entry)
  3. If serving remotely, correct the server's Content-Type header for .fpage resources

Example fix

// before
// [Content_Types].xml maps .fpage to text/plain
// after
// <Default Extension="fpage" ContentType="application/vnd.ms-package.xps-fixedpage+xml" />
Defensive patterns

Strategy: validation

Validate before calling

var part = pkg.GetPart(PackUriHelper.CreatePartUri(pageContent.Source));
bool ok = part.ContentType == "application/vnd.ms-package.xps-fixedpage+xml";

Try / catch

try { var p = pageContent.GetPage(); } catch (ApplicationException) { /* inspect part ContentType */ }

Prevention

When it happens

Trigger: GetPage/_LoadPage on a PageContent whose Source part has a MIME type other than application/vnd.ms-package.xps-fixedpage (XAML/BAML variants), e.g. an image, HTML, or text part used as page content.

Common situations: Hand-built XPS packages where page parts were added with wrong Content-Type metadata; serving pages from a web server that returns the wrong Content-Type header.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

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

            }

            ParserContext pc = new ParserContext
            {
                BaseUri = uriToLoad
            };

            if (BindUriHelper.IsXamlMimeType(mimeType))
            {
                XpsValidatingLoader loader = new XpsValidatingLoader();
                o = loader.Load(pageStream, baseUri, pc, mimeType);
            }
            else if (MS.Internal.MimeTypeMapper.BamlMime.AreTypeAndSubTypeEqual(mimeType))
            {
                o = XamlReader.LoadBaml(pageStream, pc, null, true);
            }
            else
            {
                throw new ApplicationException(SR.PageContentUnsupportedMimeType);
            }

            if (o != null && !(o is FixedPage))
            {
                throw new ApplicationException(SR.Format(SR.PageContentUnsupportedPageType, o.GetType()));
            }

            fixedPage =  (FixedPage)o;
        }

        #endregion Private Methods

        //--------------------------------------------------------------------
        //
        // Private Fields
        //
        //---------------------------------------------------------------------

View on GitHub (pinned to 81131a70a4)