{"record":{"id":"79e5571983f26a52","repo":"dotnet/wpf","slug":"sr-mustbeoftype-reachpagecontentcollectionserializerasync","errorCode":null,"errorMessage":"SR.MustBeOfType","messagePattern":"SR\\.MustBeOfType","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachPageContentCollectionSerializerAsync.cs","lineNumber":111,"sourceCode":"        /// point of the serialization process.\n        /// </summary>\n        /// <param name=\"serializableObjectContext\">\n        /// The context of the object to be serialized at this time.\n        /// </param>\n        internal\n        override\n        void\n        PersistObjectData(\n            SerializableObjectContext   serializableObjectContext\n            )\n        {\n            ArgumentNullException.ThrowIfNull(serializableObjectContext);\n\n            IEnumerable enumerableObject = serializableObjectContext.TargetObject as IEnumerable;\n\n            if (enumerableObject == null)\n            {\n                throw new XpsSerializationException(SR.Format(SR.MustBeOfType, \"serializableObjectContext.TargetObject\", typeof(IEnumerable)));\n            }\n\n            //\n            // Serialize the PageContent Items contained within the collection \n            //\n            SerializePageContents(serializableObjectContext);\n        }\n\n        internal\n        override\n        void\n        EndPersistObjectData(\n            )\n        {\n            //\n            // do nothing in this stage\n            //\n        }","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachPageContentCollectionSerializerAsync.cs#L93-L129","documentation":"Async variant of the same guard: ReachPageContentCollectionSerializerAsync.PersistObjectData throws this XpsSerializationException when the context's TargetObject is not IEnumerable. The asynchronous page-content collection serializer can only enumerate collections of PageContent items.","triggerScenarios":"Async XPS serialization where the SerializableObjectContext handed to PersistObjectData wraps a non-collection object (single PageContent, FixedPage, or unrelated type) instead of an enumerable PageContent collection.","commonSituations":"Same as the sync case but in async save paths (XpsSerializationManagerAsync): mis-wired context construction, custom serializers registered for the wrong types, refactors that changed the target's type away from a collection.","solutions":["Pass an object implementing IEnumerable (enumerating PageContent) to the async collection serializer","Use ReachPageContentSerializerAsync for individual page content items","Inspect the SerializableObjectContext.TargetObject type before the async operation is queued","Keep the serializer registration consistent with the object types in the document tree"],"exampleFix":"// before\ncontext = new SerializableObjectContext(fixedPage, \"Pages\"); // non-enumerable target\n// after\ncontext = new SerializableObjectContext(fixedDocument.Pages /* IEnumerable */, \"Pages\");","handlingStrategy":"validation","validationCode":"if (ctx.TargetObject is not IEnumerable) throw new ArgumentException(\"Async collection serializer requires IEnumerable target\");","typeGuard":"bool IsEnumerableTarget(SerializableObjectContext c) => c?.TargetObject is IEnumerable;","tryCatchPattern":null,"preventionTips":["Validate context targets before pushing async operations","Mirror sync/async target types in custom pipelines","Test async save paths with representative document trees"],"tags":["wpf","xps-serialization","async","type-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}