{"record":{"id":"4b7cd732076d0ccb","repo":"dotnet/wpf","slug":"serialization-of-this-type-of-object-is-not-supported-4b7cd7","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/NGCSerializationManagerAsync.cs","lineNumber":74,"sourceCode":"\n        /// <summary>\n        /// 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            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,false);\n                _isSimulating = true;\n            }\n\n            if(!_isBatchMode &&\n               IsDocumentSequencePrintTicketRequired(serializedObject))\n            {\n                XpsSerializationPrintTicketRequiredEventArgs printTicketEvent =\n                new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializationManagerAsync.cs#L56-L92","documentation":"The async NGCSerializationManager.SaveAsXaml explicitly checks IsSerializedObjectTypeSupported(serializedObject) and throws XpsSerializationException(SR.ReachSerialization_NotSupported) when the object's type is not on the supported serialization list. Only FixedDocumentSequence, FixedDocument, FixedPage (and related package/document types) are supported.","triggerScenarios":"Calling the async SaveAsXaml overload with a supported-type check failure — e.g. passing a Visual, UIElement, string, or arbitrary business object to NGCSerializationManagerAsync.SaveAsXaml.","commonSituations":"Migrating synchronous serialization code to the async manager and assuming any DependencyObject is serializable; attempting to serialize a plain CLR object or FlowDocument with the XPS Fixed serializer.","solutions":["Confirm the serialized object is one of: FixedDocumentSequence, FixedDocument, FixedPage (the types the manager supports).","Convert unsupported content (e.g. FlowDocument) to FixedDocument/FixedPage via DocumentPaginator / GetFixedDocumentSequence before saving.","Check the object type against IsSerializedObjectTypeSupported before calling SaveAsXaml to fail fast with your own message."],"exampleFix":"// before\nawait manager.SaveAsXamlAsync(flowDocument);\n// after\nFixedDocumentSequence fds =\n    ((IDocumentPaginatorSource)flowDocument).DocumentPaginator.Source as FixedDocumentSequence;\nawait manager.SaveAsXamlAsync(fds);","handlingStrategy":"validation","validationCode":"if (!asyncManager.IsSerializedObjectTypeSupported(obj))\n    throw new NotSupportedException($\"Async XPS save does not support {obj?.GetType().FullName}\");","typeGuard":"bool IsSupportedForAsyncSave(object o) => o is FixedDocumentSequence or FixedDocument or FixedPage;","tryCatchPattern":"try { await SaveAsXamlAsync(obj); }\ncatch (XpsSerializationException ex) { /* convert object to a supported Fixed* type or surface error to caller */ }","preventionTips":["Convert FlowDocument/visuals to FixedDocumentSequence before async save","Run the supported-type check at the API boundary","Keep a unit test asserting every serialized root type is supported"],"tags":["wpf","xps","serialization","unsupported-type","async"],"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"}