{"record":{"id":"ea9ac8f2039056a8","repo":"dotnet/wpf","slug":"sr-reachserializationasync-nongctype","errorCode":null,"errorMessage":"SR.ReachSerializationAsync_NoNgcType","messagePattern":"SR\\.ReachSerializationAsync_NoNgcType","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializerAsync.cs","lineNumber":34,"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        NGCSerializerAsync(\n            PackageSerializationManager   manager\n            )\n        {\n            ArgumentNullException.ThrowIfNull(manager);\n\n            _serializationManager = manager as NgcSerializationManagerAsync;\n\n            if(_serializationManager == null)\n            {\n                throw new XpsSerializationException(SR.ReachSerializationAsync_NoNgcType);\n            }\n        }\n\n        #endregion Constructor\n\n        #region Public Methods\n\n\n        public\n        virtual\n        void\n        AsyncOperation(\n            NGCSerializerContext context\n            )\n        {\n            if(context == null)\n            {\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializerAsync.cs#L16-L52","documentation":"The NGCSerializerAsync constructor requires an NgcSerializationManagerAsync; the manager argument is first null-checked and then cast. If the manager is any other NgcBaseSerializationManager-derived type (not the async one), an XpsSerializationException with SR.ReachSerializationAsync_NoNgcType is thrown.","triggerScenarios":"Constructing new NGCSerializerAsync(manager) where manager is null or is a synchronous NgcSerializationManager (or other manager type) instead of NgcSerializationManagerAsync.","commonSituations":"Mixing sync and async XPS serialization APIs, e.g. passing a plain NgcSerializationManager to the async serializer after refactoring code from synchronous to asynchronous saving of XPS documents.","solutions":["Pass an NgcSerializationManagerAsync instance to the NGCSerializerAsync constructor.","If synchronous serialization is intended, use NGCSerializer with the matching synchronous manager instead.","Add a compile-time or factory check so manager type and serializer type always correspond."],"exampleFix":"// before\nvar serializer = new NGCSerializerAsync(new NgcSerializationManager(stream, false));\n// after\nvar serializer = new NGCSerializerAsync(new NgcSerializationManagerAsync(stream, false));","handlingStrategy":"type-guard","validationCode":"if (manager is not NgcSerializationManagerAsync asyncManager)\n    throw new ArgumentException(\"NGCSerializerAsync requires NgcSerializationManagerAsync\");","typeGuard":"bool IsAsyncManager(NgcBaseSerializationManager m) => m is NgcSerializationManagerAsync;","tryCatchPattern":"try { var s = new NGCSerializerAsync(manager); }\ncatch (XpsSerializationException ex) {\n    // fall back to NGCSerializer for synchronous managers\n}","preventionTips":["Pair each serializer type with its matching manager type in a factory method.","Avoid mixing sync and async XPS APIs in the same pipeline.","Null-check and type-check the manager before constructing the serializer."],"tags":["wpf","xps","serialization","async","type-mismatch"],"backgroundTag":"invalid-constructor-argument","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"}