{"record":{"id":"f61385e9633d0d39","repo":"dotnet/wpf","slug":"serialization-of-this-type-of-object-is-not-supported-f61385","errorCode":null,"errorMessage":"Serialization of this type of object is not supported.","messagePattern":"Serialization of this type of object is not supported\\.","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializationManager.cs","lineNumber":66,"sourceCode":"        /// The function will serializer the avalon content to the printer spool file.\n        /// SaveAsXaml is not a propriate name. Maybe it should be \"Print\"\n        /// </summary>\n        /// <exception cref=\"ArgumentNullException\">serializedObject is NULL.</exception>\n        /// <exception cref=\"XpsSerializationException\">serializedObject is not a supported type.</exception>\n        public\n        override\n        void\n        SaveAsXaml(\n            Object  serializedObject\n            )\n        {\n            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsBegin);\n\n            ArgumentNullException.ThrowIfNull(serializedObject);\n\n            if (!IsSerializedObjectTypeSupported(serializedObject))\n            {\n                throw new XpsSerializationException(SR.ReachSerialization_NotSupported);\n            }\n\n            if(_isBatchMode && !_isSimulating)\n            {\n                XpsSerializationPrintTicketRequiredEventArgs printTicketEvent =\n                new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,\n                                                                 0);\n                OnNGCSerializationPrintTicketRequired(printTicketEvent);\n\n                StartDocument(null,true);\n                _isSimulating = true;\n            }\n\n            if(_isBatchMode)\n            {\n                StartPage();\n            }\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializationManager.cs#L48-L84","documentation":"NGCSerializationManager.SaveAsXaml validates the top-level object type against the set of types supported for XPS serialization (FixedPage, FixedDocument, FixedDocumentSequence, PageContent collections, etc.). Passing any other type throws XpsSerializationException 'Serialization of this type of object is not supported'.","triggerScenarios":"Calling SaveAsXaml with a non-supported object (e.g. a raw UIElement, Visual, string, or arbitrary CLR object) rather than an XPS document-part type.","commonSituations":"Trying to save arbitrary visuals or controls directly to XPS instead of arranging them in a FixedPage; confusion between XPS document serialization and XAML object serialization.","solutions":["Only call SaveAsXaml with supported types: FixedPage, FixedDocument, FixedDocumentSequence, or PageContent collections","Wrap arbitrary content inside a FixedPage before serializing","Check IsSerializedObjectTypeSupported before calling"],"exampleFix":"// before\nmanager.SaveAsXaml(myCanvas); // unsupported\n// after\nvar page = new FixedPage();\npage.Children.Add(myCanvas);\nmanager.SaveAsXaml(page);","handlingStrategy":"validation","validationCode":"bool IsXpsSerializableTopLevel(object o) =>\n    o is FixedPage || o is FixedDocument || o is FixedDocumentSequence ||\n    o is IEnumerable;\n\nif (!IsXpsSerializableTopLevel(obj)) throw new ArgumentException(\"Unsupported top-level type for SaveAsXaml\");\nmanager.SaveAsXaml(obj);","typeGuard":"bool IsSupportedXpsRoot(object o) =>\n    o is FixedPage or FixedDocument or FixedDocumentSequence or IEnumerable;","tryCatchPattern":"try\n{\n    manager.SaveAsXaml(obj);\n}\ncatch (XpsSerializationException ex) when (ex.Message.Contains(\"not supported\"))\n{\n    // wrap obj in a FixedPage before serializing\n}","preventionTips":["Only pass XPS document-part types to SaveAsXaml","Wrap arbitrary visuals in FixedPage first","Do not confuse XPS document serialization with general XAML serialization"],"tags":["wpf","xps","serialization","unsupported-type"],"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"}