dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_WrongPropertyTypeForFixedPage

Error message

SR.ReachSerialization_WrongPropertyTypeForFixedPage

What it means

Async counterpart of 3725: ReachFixedPageSerializerAsync.PersistObjectData throws XpsSerializationException (ReachSerialization_WrongPropertyTypeForFixedPage) when the object context is not a FixedPage. The async page serializer enforces the same type contract before SerializeObjectCore, aborting the async write otherwise.

Solutions

  1. Guarantee FixedPage instances occupy page positions in the graph
  2. Add a runtime type check before calling WriteAsync
  3. Catch XpsSerializationException and inspect the failing node type

Example fix

// before
await Task.Run(() => writer.WriteAsync(node));
// after
if (node is FixedPage page) { writer.WriteAsync(page); }
Defensive patterns

Strategy: type-guard

Validate before calling

bool ok = node is System.Windows.Documents.FixedPage;

Type guard

static bool IsFixedPage(object o) => o is System.Windows.Documents.FixedPage;

Try / catch

try { writer.WriteAsync(page); } catch (System.Windows.Xps.XpsSerializationException ex) { log.Error(ex); throw; }

Prevention

When it happens

Trigger: Async XPS write routes a non-FixedPage object to the async page serializer's PersistObjectData.

Common situations: WriteAsync with a tree containing plain Visuals or custom controls in page position; migrations from sync to async serialization that changed node types.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializerAsync.cs:242

                                                                                         treeWalker);

                    ((IXpsSerializationManagerAsync)SerializationManager).OperationStack.Push(context);

                    PrintTicket printTicket = ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket;
                    
                    if(printTicket != null)
                    {
                        PrintTicketSerializer serializer = new PrintTicketSerializer(SerializationManager);
                        serializer.SerializeObject(printTicket);
                        ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket = null;
                    }


                    SerializeObjectCore(serializableObjectContext);
                }
                else
                {
                    throw new XpsSerializationException(SR.ReachSerialization_WrongPropertyTypeForFixedPage);
                }

            }
        }

        /// <summary>
        /// This method is the one that writes out the attribute within
        /// the xml stream when serializing simple properties.
        /// </summary>
        /// <param name="serializablePropertyContext">
        /// The property that is to be serialized as an attribute at this time.
        /// </param>
        internal
        override
        void
        WriteSerializedAttribute(
            SerializablePropertyContext serializablePropertyContext
            )

View on GitHub (pinned to 81131a70a4)