dotnet/wpf · error · XpsSerializationException

Serialization of this type of object is not supported.

Error message

Serialization of this type of object is not supported.

What it means

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.

Solutions

  1. Confirm the serialized object is one of: FixedDocumentSequence, FixedDocument, FixedPage (the types the manager supports).
  2. Convert unsupported content (e.g. FlowDocument) to FixedDocument/FixedPage via DocumentPaginator / GetFixedDocumentSequence before saving.
  3. Check the object type against IsSerializedObjectTypeSupported before calling SaveAsXaml to fail fast with your own message.

Example fix

// before
await manager.SaveAsXamlAsync(flowDocument);
// after
FixedDocumentSequence fds =
    ((IDocumentPaginatorSource)flowDocument).DocumentPaginator.Source as FixedDocumentSequence;
await manager.SaveAsXamlAsync(fds);
Defensive patterns

Strategy: validation

Validate before calling

if (!asyncManager.IsSerializedObjectTypeSupported(obj))
    throw new NotSupportedException($"Async XPS save does not support {obj?.GetType().FullName}");

Type guard

bool IsSupportedForAsyncSave(object o) => o is FixedDocumentSequence or FixedDocument or FixedPage;

Try / catch

try { await SaveAsXamlAsync(obj); }
catch (XpsSerializationException ex) { /* convert object to a supported Fixed* type or surface error to caller */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializationManagerAsync.cs:74

        /// <summary>
        /// The function will serializer the avalon content to the printer spool file.
        /// SaveAsXaml is not a propriate name. Maybe it should be "Print"
        /// </summary>
        /// <exception cref="ArgumentNullException">serializedObject is NULL.</exception>
        /// <exception cref="XpsSerializationException">serializedObject is not a supported type.</exception>
        public
        override
        void
        SaveAsXaml(
            Object  serializedObject
            )
        {
            ArgumentNullException.ThrowIfNull(serializedObject);

            if (!IsSerializedObjectTypeSupported(serializedObject))
            {
                throw new XpsSerializationException(SR.ReachSerialization_NotSupported);
            }

            if(_isBatchMode && !_isSimulating)
            {
                XpsSerializationPrintTicketRequiredEventArgs printTicketEvent =
                new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,
                                                                 0);
                OnNGCSerializationPrintTicketRequired(printTicketEvent);

                StartDocument(null,false);
                _isSimulating = true;
            }

            if(!_isBatchMode &&
               IsDocumentSequencePrintTicketRequired(serializedObject))
            {
                XpsSerializationPrintTicketRequiredEventArgs printTicketEvent =
                new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedDocumentSequencePrintTicket,

View on GitHub (pinned to 81131a70a4)