{"record":{"id":"913adc5e28f467f9","repo":"dotnet/wpf","slug":"sr-reachserialization-notsupported","errorCode":null,"errorMessage":"SR.ReachSerialization_NotSupported","messagePattern":"SR\\.ReachSerialization_NotSupported","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMSerializationManager.cs","lineNumber":66,"sourceCode":"        public\n        override\n        void\n        SaveAsXaml(\n            object serializedObject\n            )\n        {\n            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsBegin);\n\n            if (_packagingPolicy.IsValid)\n            {\n\n                XmlWriter pageWriter = null;\n\n                ArgumentNullException.ThrowIfNull(serializedObject);\n\n                if (!XpsSerializationManager.IsSerializedObjectTypeSupported(serializedObject, _isBatchMode))\n                {\n                    throw new XpsSerializationException(SR.ReachSerialization_NotSupported);\n                }\n\n                if (serializedObject is DocumentPaginator)\n                {\n                    if ((serializedObject as DocumentPaginator).Source is FixedDocument &&\n                        serializedObject.GetType().ToString().Contains(\"FixedDocumentPaginator\"))\n                    {\n                        serializedObject = (serializedObject as DocumentPaginator).Source;\n                    }\n                    else\n                        if ((serializedObject as DocumentPaginator).Source is FixedDocumentSequence &&\n                            serializedObject.GetType().ToString().Contains(\"FixedDocumentSequencePaginator\"))\n                        {\n                            serializedObject = (serializedObject as DocumentPaginator).Source;\n                        }\n                }\n\n                if (_simulator == null)","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMSerializationManager.cs#L48-L84","documentation":"XpsOMSerializationManager.SaveAsXaml validates the serializedObject type against XpsSerializationManager.IsSerializedObjectTypeSupported. Types that are not supported XPS serialization roots (in the given batch mode) cause an XpsSerializationException with SR.ReachSerialization_NotSupported.","triggerScenarios":"Calling SaveAsXaml on an object that is not a DocumentPaginator, FixedDocument, FixedDocumentSequence, FixedPage, or a supported visual root in the current batch mode — e.g. passing a raw UIElement in batch mode or a random business object.","commonSituations":"Passing a non-visual or unsupported container to an XpsDocumentWriter/SaveAsXaml pipeline; mismatch between batch-mode flag and the object type; trying to serialize a ViewModel or control template directly.","solutions":["Pass one of the supported roots: FixedDocumentSequence, FixedDocument, FixedPage, DocumentPaginator, or a Visual accepted in single-item mode.","Wrap the content in a FixedPage/FixedDocument before saving (e.g. create a FixedPage and add the visual).","If serializing a Visual, use the appropriate XpsDocumentWriter.Write overload for visuals instead of SaveAsXaml on the wrong type.","Check _isBatchMode vs object type — some types are only supported in one mode."],"exampleFix":"// before\nxpsManager.SaveAsXaml(myViewModel); // NotSupported\n// after\nvar page = new FixedPage();\npage.Children.Add(myViewVisual);\npage.Measure(size);\npage.Arrange(new Rect(size));\nxpsManager.SaveAsXaml(page);","handlingStrategy":"validation","validationCode":"var supportedTypes = new[] { typeof(FixedDocumentSequence), typeof(FixedDocument), typeof(FixedPage), typeof(DocumentPaginator) };\nif (!supportedTypes.Any(t => t.IsInstanceOfType(obj)))\n    throw new InvalidOperationException(\"Object must be a FixedDocumentSequence/FixedDocument/FixedPage or DocumentPaginator\");","typeGuard":"bool IsXpsSerializableRoot(object o) =>\n    o is FixedDocumentSequence || o is FixedDocument ||\n    o is FixedPage || o is DocumentPaginator;","tryCatchPattern":"try {\n    manager.SaveAsXaml(obj);\n}\ncatch (XpsSerializationException ex) when (ex.Message.Contains(\"NotSupported\") || ex.Message.Contains(\"not supported\")) {\n    // wrong root type — wrap in FixedPage/FixedDocument and retry\n}","preventionTips":["Only pass XPS document model roots to SaveAsXaml","Wrap visuals in FixedPage before saving","Match the object type to the batch mode setting","Write unit tests around SaveAsXaml input types"],"tags":["wpf","xps","serialization","notsupported"],"backgroundTag":"unsupported-operation","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"}