dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_NotSupported

Error message

SR.ReachSerialization_NotSupported

What it means

XpsOMSerializationManagerAsync.SaveAsXaml checks the object type against XpsSerializationManager.IsSerializedObjectTypeSupported before serializing. Types that are not valid top-level serialization objects for the current batch mode (e.g. unsupported Visuals or document parts) cause XpsSerializationException(SR.ReachSerialization_NotSupported).

Solutions

  1. Serialize supported top-level objects only (FixedDocumentSequence, FixedDocument, FixedPage, and supported Visuals per IsSerializedObjectTypeResolved rules).
  2. Wrap arbitrary content in a FixedPage/FixedDocument structure before calling SaveAsXaml.
  3. Verify the IsBatchMode flag matches your usage; a type supported in single-document mode may be rejected in batch mode (or vice versa).
  4. Pre-check with XpsSerializationManager.IsSerializedObjectTypeSupported(obj, isBatchMode) before calling SaveAsXaml.

Example fix

// before
managerAsync.SaveAsXaml(myButtonVisual); // throws
// after
if (XpsSerializationManager.IsSerializedObjectTypeSupported(myButtonVisual, managerAsync.IsBatchMode))
{
    managerAsync.SaveAsXaml(myButtonVisual);
}
else
{
    var page = WrapInFixedPage(myButtonVisual);
    managerAsync.SaveAsXaml(page);
}
Defensive patterns

Strategy: validation

Validate before calling

bool ok = XpsSerializationManager.IsSerializedObjectTypeSupported(obj, isBatchMode);
if (!ok) throw new ArgumentException($"{obj.GetType().Name} is not a supported SaveAsXaml target in batch mode {isBatchMode}.");

Type guard

bool IsSupportedSaveTarget(object o, bool batch) => XpsSerializationManager.IsSerializedObjectTypeSupported(o, batch);

Try / catch

try { await managerAsync.SaveAsXamlAsync(obj); }
catch (XpsSerializationException ex) when (ex.Message.Contains("NotSupported")) { /* wrap in FixedPage or use the correct serializer */ }

Prevention

When it happens

Trigger: Calling SaveAsXaml with a serializedObject whose type is not in the supported set for IsBatchMode — e.g. passing a plain UIElement/Visual or an out-of-order document part to the async XPS OM serializer.

Common situations: Passing arbitrary WPF visuals (buttons, panels) directly to SaveAsXaml instead of wrapping them in FixedPage/FixedDocument; batch-mode flag mismatch so an otherwise valid type is rejected; porting code from the sync XpsSerializationManager with different type rules.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMSerializationManagerAsync.cs:48

            _batchOperationQueue = new Queue();
        }

        #endregion Constructor

        #region packageSerializationManager override

        public
        override
        void
        SaveAsXaml(
            Object serializedObject
            )
        {
            ArgumentNullException.ThrowIfNull(serializedObject);

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

            if (Simulator == null)
            {
                Simulator = new XpsOMHierarchySimulator(this,
                                                         serializedObject);
            }

            if (!IsSimulating)
            {
                Simulator.BeginConfirmToXPSStructure(IsBatchMode);
                IsSimulating = true;
            }

            if (IsBatchMode)
            {
                //
                // Add the Visual received in to the queue

View on GitHub (pinned to 81131a70a4)