dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_NoSerializer

Error message

SR.ReachSerialization_NoSerializer

What it means

The synchronous DocumentReference serializer throws XpsSerializationException in PersistObjectData when it obtains a FixedDocument for the reference but no serializer exists to write it. The source comment says 'This shouldn't ever happen', meaning it guards an internal invariant: a resolved document must always have a matching serializer. Hitting it indicates the serializer manager's type-to-serializer lookup failed for the document instance.

Solutions

  1. Serialize only stock FixedDocument instances referenced through DocumentReference
  2. Register a custom serializer for the document type with the serialization manager
  3. Catch XpsSerializationException and inspect the document's runtime type to find the unregistered one
Defensive patterns

Strategy: try-catch

Validate before calling

bool ok = documentReference.GetDocument?.Invoke() is System.Windows.Documents.FixedDocument;

Type guard

static bool HasSerializableDocument(System.Windows.Documents.DocumentReference dr) => dr.GetDocument?.Invoke() is System.Windows.Documents.FixedDocument;

Try / catch

try { writer.Write(documentReference); } catch (System.Windows.Xps.XpsSerializationException ex) { log.Error("Document serializer missing for type " + documentReference.GetDocument().GetType(), ex); throw; }

Prevention

When it happens

Trigger: PersistObjectData resolves the DocumentReference's GetDocument() result, but SerializationManager cannot create a serializer for that document's concrete type (unregistered/custom FixedDocument-derived type, or null-type object).

Common situations: Custom document classes deriving from FixedDocument without a registered serializer; running a trimmed/IL-linked build where WPF serialization internals were stripped; reflection-based document creation yielding unexpected types.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentReferenceSerializer.cs:69

                if (!document.IsInitialized)
                {
                    // Give a parser item a kick
                    document.Dispatcher.Invoke(DispatcherPriority.ApplicationIdle,
                        new DispatcherOperationCallback(Idle), null);
                }

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

                    if(serializer!=null)
                    {
                        serializer.SerializeObject(document);
                    }
                    else
                    {
                        // This shouldn't ever happen.
                        throw new XpsSerializationException(SR.ReachSerialization_NoSerializer);
                    }
                }
            }
            else
            {
                // What about this case?  Is IsComplexValue something we really want to check for this?
            }
        }
    };
}

View on GitHub (pinned to 81131a70a4)