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

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'.

Solutions

  1. Only call SaveAsXaml with supported types: FixedPage, FixedDocument, FixedDocumentSequence, or PageContent collections
  2. Wrap arbitrary content inside a FixedPage before serializing
  3. Check IsSerializedObjectTypeSupported before calling

Example fix

// before
manager.SaveAsXaml(myCanvas); // unsupported
// after
var page = new FixedPage();
page.Children.Add(myCanvas);
manager.SaveAsXaml(page);
Defensive patterns

Strategy: validation

Validate before calling

bool IsXpsSerializableTopLevel(object o) =>
    o is FixedPage || o is FixedDocument || o is FixedDocumentSequence ||
    o is IEnumerable;

if (!IsXpsSerializableTopLevel(obj)) throw new ArgumentException("Unsupported top-level type for SaveAsXaml");
manager.SaveAsXaml(obj);

Type guard

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

Try / catch

try
{
    manager.SaveAsXaml(obj);
}
catch (XpsSerializationException ex) when (ex.Message.Contains("not supported"))
{
    // wrap obj in a FixedPage before serializing
}

Prevention

When it happens

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

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

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/f61385e9633d0d39. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializationManager.cs:66

        /// 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
            )
        {
            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsBegin);

            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,true);
                _isSimulating = true;
            }

            if(_isBatchMode)
            {
                StartPage();
            }

View on GitHub (pinned to 81131a70a4)