{"record":{"id":"be2ca574f17e6cdb","repo":"dotnet/wpf","slug":"sr-reachserialization-noserializer-be2ca5","errorCode":null,"errorMessage":"SR.ReachSerialization_NoSerializer","messagePattern":"SR\\.ReachSerialization_NoSerializer","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentReferenceSerializer.cs","lineNumber":69,"sourceCode":"                if (!document.IsInitialized)\n                {\n                    // Give a parser item a kick\n                    document.Dispatcher.Invoke(DispatcherPriority.ApplicationIdle,\n                        new DispatcherOperationCallback(Idle), null);\n                }\n\n                if(document != null)\n                {\n                    ReachSerializer serializer = SerializationManager.GetSerializer(document);\n\n                    if(serializer!=null)\n                    {\n                        serializer.SerializeObject(document);\n                    }\n                    else\n                    {\n                        // This shouldn't ever happen.\n                        throw new XpsSerializationException(SR.ReachSerialization_NoSerializer);\n                    }\n                }\n            }\n            else\n            {\n                // What about this case?  Is IsComplexValue something we really want to check for this?\n            }\n        }\n    };\n}\n","sourceCodeStart":51,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentReferenceSerializer.cs#L51-L80","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Serialize only stock FixedDocument instances referenced through DocumentReference","Register a custom serializer for the document type with the serialization manager","Catch XpsSerializationException and inspect the document's runtime type to find the unregistered one"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"bool ok = documentReference.GetDocument?.Invoke() is System.Windows.Documents.FixedDocument;","typeGuard":"static bool HasSerializableDocument(System.Windows.Documents.DocumentReference dr) => dr.GetDocument?.Invoke() is System.Windows.Documents.FixedDocument;","tryCatchPattern":"try { writer.Write(documentReference); } catch (System.Windows.Xps.XpsSerializationException ex) { log.Error(\"Document serializer missing for type \" + documentReference.GetDocument().GetType(), ex); throw; }","preventionTips":["Use stock FixedDocument via DocumentReference.GetDocument","Register serializers for any custom document types","Test serialization of every document type in the app"],"tags":["xps","wpf","serialization","dotnet"],"backgroundTag":"internal-invariant-violation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}