dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_NotSupported

Error message

SR.ReachSerialization_NotSupported

What it means

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.

Solutions

  1. Pass one of the supported roots: FixedDocumentSequence, FixedDocument, FixedPage, DocumentPaginator, or a Visual accepted in single-item mode.
  2. Wrap the content in a FixedPage/FixedDocument before saving (e.g. create a FixedPage and add the visual).
  3. If serializing a Visual, use the appropriate XpsDocumentWriter.Write overload for visuals instead of SaveAsXaml on the wrong type.
  4. Check _isBatchMode vs object type — some types are only supported in one mode.

Example fix

// before
xpsManager.SaveAsXaml(myViewModel); // NotSupported
// after
var page = new FixedPage();
page.Children.Add(myViewVisual);
page.Measure(size);
page.Arrange(new Rect(size));
xpsManager.SaveAsXaml(page);
Defensive patterns

Strategy: validation

Validate before calling

var supportedTypes = new[] { typeof(FixedDocumentSequence), typeof(FixedDocument), typeof(FixedPage), typeof(DocumentPaginator) };
if (!supportedTypes.Any(t => t.IsInstanceOfType(obj)))
    throw new InvalidOperationException("Object must be a FixedDocumentSequence/FixedDocument/FixedPage or DocumentPaginator");

Type guard

bool IsXpsSerializableRoot(object o) =>
    o is FixedDocumentSequence || o is FixedDocument ||
    o is FixedPage || o is DocumentPaginator;

Try / catch

try {
    manager.SaveAsXaml(obj);
}
catch (XpsSerializationException ex) when (ex.Message.Contains("NotSupported") || ex.Message.Contains("not supported")) {
    // wrong root type — wrap in FixedPage/FixedDocument and retry
}

Prevention

When it happens

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

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

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

Appendix: source

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

        public
        override
        void
        SaveAsXaml(
            object serializedObject
            )
        {
            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsBegin);

            if (_packagingPolicy.IsValid)
            {

                XmlWriter pageWriter = null;

                ArgumentNullException.ThrowIfNull(serializedObject);

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

                if (serializedObject is DocumentPaginator)
                {
                    if ((serializedObject as DocumentPaginator).Source is FixedDocument &&
                        serializedObject.GetType().ToString().Contains("FixedDocumentPaginator"))
                    {
                        serializedObject = (serializedObject as DocumentPaginator).Source;
                    }
                    else
                        if ((serializedObject as DocumentPaginator).Source is FixedDocumentSequence &&
                            serializedObject.GetType().ToString().Contains("FixedDocumentSequencePaginator"))
                        {
                            serializedObject = (serializedObject as DocumentPaginator).Source;
                        }
                }

                if (_simulator == null)

View on GitHub (pinned to 81131a70a4)