dotnet/wpf · error · ArgumentException

SR.ReachSerialization_ExpectedFixedPage

Error message

SR.ReachSerialization_ExpectedFixedPage

What it means

NgcSerializer.SerializeObject (the FixedPage overload) casts serializedObject to FixedPage and throws ArgumentException(SR.ReachSerialization_ExpectedFixedPage) when the cast fails. The serializer can only write FixedPage content at this level of the XPS hierarchy.

Solutions

  1. Pass a FixedPage to this overload; convert other content into a FixedPage first.
  2. Route FixedDocument/FixedDocumentSequence objects to their dedicated serializer overloads.
  3. Guard with 'is FixedPage' before invoking.

Example fix

// before
pageSerializer.SerializeObject(fixedDocument);
// after
if (fixedDocument is FixedPage fp) pageSerializer.SerializeObject(fp);
else docSerializer.SerializeObject(fixedDocument);
Defensive patterns

Strategy: type-guard

Validate before calling

if (obj is not FixedPage)
    throw new ArgumentException("Page serializer requires a FixedPage instance");

Type guard

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

Try / catch

try { pageSerializer.SerializeObject(obj); }
catch (ArgumentException ex) when (ex.Message.Contains("FixedPage")) { /* dispatch to the correct serializer level */ }

Prevention

When it happens

Trigger: Calling this SerializeObject overload with a non-FixedPage object (e.g. a FixedDocument or a Canvas), so the `as FixedPage` cast returns null.

Common situations: Serializing raw page visuals directly; wiring the page-level serializer to document-level objects after a refactor of the serialization chain.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializer.cs:156

        /// <summary>
        ///
        /// </summary>
        public
        override
        void
        SerializeObject(
            Object serializedObject
            )
        {
            NgcSerializationManager ngcManager = SerializationManager as NgcSerializationManager;
            ArgumentNullException.ThrowIfNull(serializedObject);

            FixedPage fp = serializedObject as FixedPage;
            if( fp == null )
            {

               throw new ArgumentException(SR.ReachSerialization_ExpectedFixedPage);
            }

            bool bManualStartDoc = ngcManager.StartPage();

            Size pageSize = new Size(fp.Width, fp.Height);
            ngcManager.PageSize = pageSize;

            Visual visual = (Visual)serializedObject as Visual;

            if (visual != null)
            {
                ngcManager.WalkVisual(visual);
            }

            ngcManager.EndPage();
            if (bManualStartDoc)
            {
                ngcManager.EndDocument();

View on GitHub (pinned to 81131a70a4)