dotnet/wpf · error · XpsSerializationException

Cannot find the appropriate serializer.

Error message

Cannot find the appropriate serializer.

What it means

NgcSerializationManager.SaveAsXaml could not find a registered ReachSerializer capable of serializing the type of the object passed to it. The WPF XPS serialization pipeline keeps a table of supported types (FixedDocumentSequence, FixedDocument, FixedPage, etc.) and throws XpsSerializationException(SR.ReachSerialization_NoSerializer) when GetSerializer returns null for the supplied object.

Solutions

  1. Ensure the object passed to SaveAsXaml is a FixedDocumentSequence, FixedDocument, or FixedPage.
  2. If saving arbitrary visuals, wrap them in a FixedPage (or use XpsDocument.ConvertToXps / XpsDocumentWriter with a VisualsToXpsDocument writer) instead of SaveAsXaml.
  3. Verify you are using the correct serialization manager (NgcSerializationManager vs XpsSerializationManager) for the object type.

Example fix

// before
manager.SaveAsXaml(myCanvas);
// after
FixedPage page = new FixedPage();
page.Children.Add(myCanvas);
page.Width = 816; page.Height = 1056;
manager.SaveAsXaml(page);
Defensive patterns

Strategy: type-guard

Validate before calling

bool canSave = obj is FixedDocumentSequence || obj is FixedDocument || obj is FixedPage;
if (!canSave) throw new NotSupportedException($"No XPS serializer for {obj?.GetType().FullName}");

Type guard

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

Try / catch

try { manager.SaveAsXaml(obj); }
catch (XpsSerializationException ex) when (ex.Message.Contains("serializer")) { /* log unsupported type, fall back to wrapping in FixedPage */ }

Prevention

When it happens

Trigger: Calling SaveAsXaml on an NGC/NgcSerializationManager with an object whose type has no registered serializer — e.g. a raw Visual, Canvas, or any class that is not one of the supported Fixed* container types.

Common situations: Passing a UIElement or custom control to XpsDocument/XpsSerializationManager.SaveAsXaml expecting it to be converted to XPS; calling SaveAsXaml directly on a FixedPage instead of routing through the proper document hierarchy.

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

Appendix: source

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

            if(reachSerializer != null)
            {
                //
                // Call top-level type serializer, it will walk through the contents and
                // all CLR and DP properties of the object and invoke the proper serializer
                // and typeconverter respectively
                //

                reachSerializer.SerializeObject(serializedObject);

                if(_isBatchMode)
                {
                    EndPage();
                }
            }
            else
            {
                throw new XpsSerializationException(SR.ReachSerialization_NoSerializer);
            }

            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSaveXpsEnd);
        }


        /// <summary>
        ///
        /// </summary>
        public
        void
        Cancel(
            )
        {
            if(_startDocCnt != 0 )
            {
                _device.AbortDocument();
                _startDocCnt = 0;

View on GitHub (pinned to 81131a70a4)