dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_WrongPropertyTypeForPageContent

Error message

SR.ReachSerialization_WrongPropertyTypeForPageContent

What it means

ReachPageContentSerializer.PersistObjectData throws XpsSerializationException(SR.ReachSerialization_WrongPropertyTypeForPageContent) when the SerializableObjectContext's target object is not a PageContent (the expected property type). This serializer exists solely for PageContent objects; anything else is invalid input to it.

Solutions

  1. Ensure the object passed to ReachPageContentSerializer is a PageContent instance
  2. Use ReachPageContentCollectionSerializer for collections and the FixedPage serializer for FixedPage objects
  3. Fix the context construction so TargetObject is the PageContent node
  4. Check custom serializer-to-type registrations for mismatches

Example fix

// before
var serializer = new ReachPageContentSerializer(manager);
serializer.SerializeObject(fixedPage); // wrong type
// after
serializer.SerializeObject(pageContent); // PageContent wraps the FixedPage
serializer.SerializeObject(((PageContent)target).Child == null ? pageContent : pageContent);
Defensive patterns

Strategy: type-guard

Validate before calling

if (target is not PageContent) throw new ArgumentException("ReachPageContentSerializer requires a PageContent");

Type guard

bool IsPageContent(object o) => o is PageContent;

Prevention

When it happens

Trigger: Calling SerializeObject on ReachPageContentSerializer with a target that is not System.Windows.Documents.PageContent — e.g. a FixedPage directly, a UIElement, or a collection (which belongs to the collection serializer).

Common situations: Custom serialization drivers invoking page-level serializer with the wrong node of the document tree; refactorings that changed which serializer handles which type; manual context construction with wrong TargetObject.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachPageContentSerializer.cs:95

                        if( e.Modified )
                        {
                            printTicket =  e.PrintTicket;
                        }
                        Toolbox.Layout(fixedPage, printTicket);
                        
                        ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket = printTicket;

                        serializer.SerializeObject(fixedPage);
                    }
                    else
                    {
                        throw new XpsSerializationException(SR.ReachSerialization_NoSerializer);
                    }
                }
            }
            else
            {
                throw new XpsSerializationException(SR.ReachSerialization_WrongPropertyTypeForPageContent);
            }
        }

        #endregion Internal Methods
    };
}

View on GitHub (pinned to 81131a70a4)