dotnet/wpf · error · ApplicationException

SR.Format(SR.PageContentUnsupportedPageType, o.GetType())

Error message

SR.Format(SR.PageContentUnsupportedPageType, o.GetType())

What it means

_LoadPageImpl throws ApplicationException with SR.PageContentUnsupportedPageType when the XAML/BAML parse succeeds but the root object is not a FixedPage. A PageContent can only present FixedPage content, so any other root element type is rejected.

Solutions

  1. Make the loaded XAML root element a <FixedPage>
  2. Move non-FixedPage content inside a FixedPage root
  3. Re-author or convert the page part to the XPS FixedPage schema

Example fix

// before
<Canvas xmlns=...> ... </Canvas>
// after
<FixedPage xmlns=... xmlns:x=... Width="816" Height="1056"> ... </FixedPage>
Defensive patterns

Strategy: validation

Validate before calling

// after load, before GetPage:
// parse root element name and require "FixedPage"

Type guard

bool IsFixedPage(object o) => o is FixedPage;

Try / catch

try { var p = pageContent.GetPage(); } catch (ApplicationException) { /* root element not FixedPage: fix XAML */ }

Prevention

When it happens

Trigger: GetPage on a PageContent whose Source XAML has a root element other than FixedPage (e.g. a raw Canvas, UserControl, or FlowDocument).

Common situations: Authoring page XAML with the wrong root element; reusing application XAML files as XPS page parts; migration/refactor that changed the page's root type.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

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

            };

            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
        //
        //---------------------------------------------------------------------

        #region Private Fields
        private WeakReference _pageRef;         // weak ref to page's root visual
        private FixedPage     _child;              // directly hosted page stream
        private PageContentAsyncResult  _asyncOp;
        private HybridDictionary  _pendingStreams;

View on GitHub (pinned to 81131a70a4)