{"record":{"id":"549abf58d7ee38c5","repo":"dotnet/wpf","slug":"sr-reachserialization-notxpsserializationmanagerasync","errorCode":null,"errorMessage":"SR.ReachSerialization_NotXpsSerializationManagerAsync","messagePattern":"SR\\.ReachSerialization_NotXpsSerializationManagerAsync","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializerAsync.cs","lineNumber":44,"sourceCode":"        /// <summary>\n        /// Constructor for class ReachSerializer\n        /// </summary>\n        /// <param name=\"manager\">\n        /// The serializtion manager, the services of which are\n        /// used later for the serialization process of the type.\n        /// </param>\n        public\n        ReachSerializerAsync(\n            PackageSerializationManager   manager\n            )\n        {\n            ArgumentNullException.ThrowIfNull(manager);\n\n            _serializationManager = manager as IXpsSerializationManagerAsync;\n\n            if(_serializationManager == null)\n            {\n                throw new XpsSerializationException(SR.ReachSerialization_NotXpsSerializationManagerAsync);\n            }\n\n            _xmlWriter            = null;\n        }\n\n        #endregion Constructor\n\n        #region Public Methods\n\n\n        public\n        virtual\n        void\n        AsyncOperation(\n            ReachSerializerContext context\n            )\n        {\n            if(context == null)","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializerAsync.cs#L26-L62","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Create the manager via the async path, e.g. new XpsSerializationManagerAsync(new XpsPackagingPolicy(package), false), and pass that to the async serializer","Do not pass a synchronous XpsSerializationManager to async serializers; keep sync and async pipelines separate","Check with a cast (manager is IXpsSerializationManagerAsync) before constructing the serializer"],"exampleFix":"// before\nvar manager = new XpsSerializationManager(new XpsPackagingPolicy(package), false);\nvar asyncSerializer = new ReachSerializerAsync(manager);\n// after\nvar manager = new XpsSerializationManagerAsync(new XpsPackagingPolicy(package), false);\nvar asyncSerializer = new ReachSerializerAsync(manager);","handlingStrategy":"type-guard","validationCode":"if (manager is not IXpsSerializationManagerAsync) throw new ArgumentException(\"Manager must be an XpsSerializationManagerAsync\");","typeGuard":"bool IsAsyncManager(IXpsSerializationManager m) => m is IXpsSerializationManagerAsync;","tryCatchPattern":"try { var s = new ReachSerializerAsync(manager); }\ncatch (XpsSerializationException) { manager = new XpsSerializationManagerAsync(policy, false); }","preventionTips":["Use XpsSerializationManagerAsync for all async serialization","Keep sync and async manager instances separate","Cast-check managers before passing them to async APIs"],"tags":["wpf","xps","serialization","async","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}