dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_NotXpsSerializationManagerAsync

Error message

SR.ReachSerialization_NotXpsSerializationManagerAsync

What it means

The ReachSerializerAsync constructor accepts a manager but requires it to implement IXpsSerializationManagerAsync, not just the base interface. If the cast fails (manager is a synchronous XpsSerializationManager or another IXpsSerializationManager implementation), asynchronous serialization cannot proceed and an XpsSerializationException is thrown immediately.

Solutions

  1. Create the manager via the async path, e.g. new XpsSerializationManagerAsync(new XpsPackagingPolicy(package), false), and pass that to the async serializer
  2. Do not pass a synchronous XpsSerializationManager to async serializers; keep sync and async pipelines separate
  3. Check with a cast (manager is IXpsSerializationManagerAsync) before constructing the serializer

Example fix

// before
var manager = new XpsSerializationManager(new XpsPackagingPolicy(package), false);
var asyncSerializer = new ReachSerializerAsync(manager);
// after
var manager = new XpsSerializationManagerAsync(new XpsPackagingPolicy(package), false);
var asyncSerializer = new ReachSerializerAsync(manager);
Defensive patterns

Strategy: type-guard

Validate before calling

if (manager is not IXpsSerializationManagerAsync) throw new ArgumentException("Manager must be an XpsSerializationManagerAsync");

Type guard

bool IsAsyncManager(IXpsSerializationManager m) => m is IXpsSerializationManagerAsync;

Try / catch

try { var s = new ReachSerializerAsync(manager); }
catch (XpsSerializationException) { manager = new XpsSerializationManagerAsync(policy, false); }

Prevention

When it happens

Trigger: Constructing ReachSerializerAsync (directly or via async document/page serializers) and passing a synchronous XpsSerializationManager — e.g. created with batchingMode but used through the sync interface — or any manager object that only implements IXpsSerializationManager.

Common situations: Mixing sync and async XPS APIs: obtaining a manager from synchronous code paths (XpsDocument.GetFixedDocumentSequence / sync SaveAsXaml) and handing it to async serialization (e.g. via BeginWrite on an XpsDocument created for async use).

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializerAsync.cs:44

        /// <summary>
        /// Constructor for class ReachSerializer
        /// </summary>
        /// <param name="manager">
        /// The serializtion manager, the services of which are
        /// used later for the serialization process of the type.
        /// </param>
        public
        ReachSerializerAsync(
            PackageSerializationManager   manager
            )
        {
            ArgumentNullException.ThrowIfNull(manager);

            _serializationManager = manager as IXpsSerializationManagerAsync;

            if(_serializationManager == null)
            {
                throw new XpsSerializationException(SR.ReachSerialization_NotXpsSerializationManagerAsync);
            }

            _xmlWriter            = null;
        }

        #endregion Constructor

        #region Public Methods


        public
        virtual
        void
        AsyncOperation(
            ReachSerializerContext context
            )
        {
            if(context == null)

View on GitHub (pinned to 81131a70a4)