dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_WrongPropertyTypeForFixedDocument

Error message

SR.ReachSerialization_WrongPropertyTypeForFixedDocument

What it means

Async version of error 3723: ReachFixedDocumentSerializerAsync.PersistObjectData throws XpsSerializationException when the context object is not the FixedDocument type it requires. It fails fast before SerializeObjectCore so that malformed graphs never produce a partially written async XPS package.

Solutions

  1. Verify the object passed to WriteAsync is a FixedDocument
  2. Nest FixedPage content inside PageContent entries of document.Pages
  3. Catch XpsSerializationException and run a type audit of the visual/document tree

Example fix

// before
if (!(obj is FixedDocument)) { /* serialized anyway */ }
// after
if (obj is FixedDocument doc) { xpsWriter.WriteAsync(doc); }
Defensive patterns

Strategy: type-guard

Validate before calling

bool ok = obj is System.Windows.Documents.FixedDocument;

Type guard

static bool IsFixedDocument(object o) => o is System.Windows.Documents.FixedDocument;

Try / catch

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

Prevention

When it happens

Trigger: WriteAsync path routes an object to the async FixedDocument serializer whose SerializableObjectContext.TargetObject is not a FixedDocument.

Common situations: Same as sync case: manual object trees, FixedPage placed where FixedDocument is expected, custom subclasses changing the expected runtime type during async writes.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializerAsync.cs:202

                    ((IXpsSerializationManager)SerializationManager).OnXPSSerializationPrintTicketRequired(e);

                    //
                    // Serialize the data for the PrintTicket
                    //
                    if(e.Modified)
                    {
                        if(e.PrintTicket != null)
                        {
                            PrintTicketSerializerAsync serializer = new PrintTicketSerializerAsync(SerializationManager);
                            serializer.SerializeObject(e.PrintTicket);
                        }
                    }

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

        internal
        override
        void
        EndPersistObjectData(
            )
        {
            //
            // Clear off the table from the packaging policy
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageCrcTable = null;
            
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.ImageUriHashTable = null;

View on GitHub (pinned to 81131a70a4)