dotnet/wpf · error · XpsSerializationException

Serialized PageContent is not a complex property.

Error message

Serialized PageContent is not a complex property.

What it means

NGCPageContentSerializerAsync.PersistObjectData requires the serialized object context to be a complex property. When the PageContent context is not a complex property (wrong property kind for a page), it throws XpsSerializationException 'Serialized PageContent is not a complex property'.

Solutions

  1. Serialize PageContent as part of the normal FixedDocument/FixedPage serialization flow
  2. Ensure the manager pushes a complex-property context for PageContent
  3. Avoid manually constructing contexts; use the standard serialization manager entry points
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    manager.SaveAsXaml(pageContent);
}
catch (XpsSerializationException ex) when (ex.Message.Contains("complex property"))
{
    // use standard document walk instead of manual contexts
}

Prevention

When it happens

Trigger: Asynchronously serializing a PageContent whose object context was created as a non-complex (simple/dependency) property instead of a complex property context.

Common situations: Internal routing bugs in custom serialization managers, or calling SaveAsXaml with an object whose context construction skipped the complex-property path (e.g. serializing page content outside a FixedDocument walk).

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/b0561182f83e1ee4. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCPageContentSerializerAsync.cs:104

        /// </param>
        internal
        override
        void
        PersistObjectData(
            SerializableObjectContext   serializableObjectContext
            )
        {
            if(serializableObjectContext.IsComplexValue)
            {
                NGCSerializerContext context = new NGCSerializerContext(this,
                                                                        serializableObjectContext,
                                                                         SerializerAction.serializePage);

                ((NgcSerializationManagerAsync)SerializationManager).OperationStack.Push(context);
            }
            else
            {
                throw new XpsSerializationException(SR.ReachSerialization_WrongPropertyTypeForPageContent);
            }
        }

        private
        void
        SerializePage(
            SerializableObjectContext   serializableObjectContext
            )
        {
            FixedPage fixedPage = Toolbox.GetPageRoot(serializableObjectContext.TargetObject);

            if(fixedPage != null)
            {
                ReachSerializer serializer = SerializationManager.GetSerializer(fixedPage);

                if(serializer!=null)
                {
                    NgcSerializationManagerAsync manager = SerializationManager as NgcSerializationManagerAsync;

View on GitHub (pinned to 81131a70a4)