dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_MustHaveSerializationManager

Error message

SR.ReachSerialization_MustHaveSerializationManager

What it means

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.

Solutions

  1. Create and pass an XpsSerializationManager (via XpsPackagingPolicy) when constructing the serializer instead of null
  2. Drive serialization through XpsDocument/XpsSerializationManager public APIs rather than instantiating ReachSerializer subclasses directly
  3. Assert SerializationManager is assigned before calling SerializeObject

Example fix

// before
var serializer = new ReachPageSerializer(null);
serializer.SerializeObject(page);
// after
var manager = new XpsSerializationManager(new XpsPackagingPolicy(package), false);
var serializer = new ReachPageSerializer(manager);
serializer.SerializeObject(page);
Defensive patterns

Strategy: validation

Validate before calling

if (serializer.SerializationManager == null) throw new InvalidOperationException("Serializer not initialized with an XpsSerializationManager");

Try / catch

try { serializer.SerializeObject(obj); }
catch (XpsSerializationException ex) when (ex.Message.Contains("SerializationManager")) { /* re-init manager and retry */ }

Prevention

When it happens

Trigger: 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.

Common situations: Manually instantiating Reach*Serializer classes instead of driving serialization through XpsSerializationManager/XpsDocument; custom walker code that constructs serializers with a null manager.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializer.cs:73

        /// <summary>
        /// The main method that is called to serialize the object of
        /// that given type.
        /// </summary>
        /// <param name="serializedObject">
        /// Instance of object to be serialized.
        /// </param>
        public
        virtual
        void
        SerializeObject(
            Object serializedObject
            )
        {
            ArgumentNullException.ThrowIfNull(serializedObject);
            if (SerializationManager == null)
            {
                throw new XpsSerializationException(SR.ReachSerialization_MustHaveSerializationManager);
            }
            //
            // At this stage discover the graph of properties of the object that
            // need to be serialized
            //                      
            SerializableObjectContext serializableObjectContext = DiscoverObjectData(serializedObject,
                                                                                     null);

            if(serializableObjectContext!=null)
            {
                //
                // Push the object at hand on the context stack
                //
                SerializationManager.GraphContextStack.Push(serializableObjectContext);

                //
                // At this stage we should start streaming the markup representing the
                // object graph to the corresponding destination

View on GitHub (pinned to 81131a70a4)