{"record":{"id":"3e1466ab2ae558fb","repo":"dotnet/wpf","slug":"sr-reachserialization-musthaveserializationmanager-3e1466","errorCode":null,"errorMessage":"SR.ReachSerialization_MustHaveSerializationManager","messagePattern":"SR\\.ReachSerialization_MustHaveSerializationManager","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializer.cs","lineNumber":73,"sourceCode":"\n        /// <summary>\n        /// The main method that is called to serialize the object of\n        /// that given type.\n        /// </summary>\n        /// <param name=\"serializedObject\">\n        /// Instance of object to be serialized.\n        /// </param>\n        public\n        virtual\n        void\n        SerializeObject(\n            Object serializedObject\n            )\n        {\n            ArgumentNullException.ThrowIfNull(serializedObject);\n            if (SerializationManager == null)\n            {\n                throw new XpsSerializationException(SR.ReachSerialization_MustHaveSerializationManager);\n            }\n            //\n            // At this stage discover the graph of properties of the object that\n            // need to be serialized\n            //                      \n            SerializableObjectContext serializableObjectContext = DiscoverObjectData(serializedObject,\n                                                                                     null);\n\n            if(serializableObjectContext!=null)\n            {\n                //\n                // Push the object at hand on the context stack\n                //\n                SerializationManager.GraphContextStack.Push(serializableObjectContext);\n\n                //\n                // At this stage we should start streaming the markup representing the\n                // object graph to the corresponding destination","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializer.cs#L55-L91","documentation":"ReachSerializer.SerializeObject refuses to serialize an object when its SerializationManager property is null. The serializer needs the manager to discover object data, write parts, and resolve packaging; without it serialization cannot proceed, so a synchronous XpsSerializationException is thrown immediately after the null check on the object itself.","triggerScenarios":"Calling SerializeObject on a ReachSerializer instance (e.g. a ReachPageSerializer or a serializer obtained directly) that was never associated with an IXpsSerializationManager, or using one after its manager reference was cleared.","commonSituations":"Manually instantiating Reach*Serializer classes instead of driving serialization through XpsSerializationManager/XpsDocument; custom walker code that constructs serializers with a null manager.","solutions":["Create and pass an XpsSerializationManager (via XpsPackagingPolicy) when constructing the serializer instead of null","Drive serialization through XpsDocument/XpsSerializationManager public APIs rather than instantiating ReachSerializer subclasses directly","Assert SerializationManager is assigned before calling SerializeObject"],"exampleFix":"// before\nvar serializer = new ReachPageSerializer(null);\nserializer.SerializeObject(page);\n// after\nvar manager = new XpsSerializationManager(new XpsPackagingPolicy(package), false);\nvar serializer = new ReachPageSerializer(manager);\nserializer.SerializeObject(page);","handlingStrategy":"validation","validationCode":"if (serializer.SerializationManager == null) throw new InvalidOperationException(\"Serializer not initialized with an XpsSerializationManager\");","typeGuard":null,"tryCatchPattern":"try { serializer.SerializeObject(obj); }\ncatch (XpsSerializationException ex) when (ex.Message.Contains(\"SerializationManager\")) { /* re-init manager and retry */ }","preventionTips":["Always construct serializers with a valid manager","Prefer XpsDocument/XpsSerializationManager public APIs over internal serializer classes","Initialize manager and serializer together in one factory method"],"tags":["wpf","xps","serialization","null-reference"],"backgroundTag":"missing-required-config","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"}