dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_NoSerializer

Error message

SR.ReachSerialization_NoSerializer

What it means

XpsSerializationException thrown by the async DocumentReferenceCollection serializer when it walks a collection and encounters an item for which no serializer can be produced. The serialization manager cannot find (or construct) a serializer for the object graph node, so the XPS package cannot be written and the operation aborts. The code comment ('should we throw if this is not a DocumentReference or just not do anything?') indicates the collection contained an object that is not a DocumentReference.

Solutions

  1. Ensure every item in the serialized collection is a System.Windows.Documents.DocumentReference
  2. Verify the object's type has a registered serializer with the XpsSerializationManager (use built-in types or register a custom serializer)
  3. Catch XpsSerializationException around the save/WriteAsync call and log which collection item failed before rethrowing

Example fix

// before
sequence.DocumentReferences.Add(fixedDocument); // wrong type
// after
DocumentReference dr = new DocumentReference { GetDocument = () => fixedDocument };
sequence.DocumentReferences.Add(dr);
Defensive patterns

Strategy: validation

Validate before calling

static bool IsSerializableCollection(System.Windows.Documents.DocumentReferenceCollection c) => c != null && c.Cast<object>().All(i => i is System.Windows.Documents.DocumentReference);

Type guard

static bool IsDocumentReference(object o) => o is System.Windows.Documents.DocumentReference;

Try / catch

try { writer.WriteAsync(sequence); } catch (System.Windows.Xps.XpsSerializationException ex) { log.Error("No serializer for collection item", ex); throw; }

Prevention

When it happens

Trigger: Calling ReachDocumentReferenceCollectionSerializerAsync.SerializeDocumentReference (via SerializeNextDocumentReference) on a collection whose current item is not a DocumentReference, or an object type not registered with the serializer manager so serializer.SerializeObject resolves to null.

Common situations: Custom FixedDocumentSequence/DocumentReference graphs built manually; passing a FixedDocument into a DocumentReference collection by mistake; type missing from the serializer map after a .NET/WPF version change.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentReferenceCollectionSerializerAsync.cs:169

        /// <summary>
        ///     Called to serialize a single DocumentReference
        /// </summary>
        private 
        void
        SerializeDocumentReference(
            object documentReference
            )
        {
            ReachSerializer serializer = SerializationManager.GetSerializer(documentReference);

            if(serializer!=null)
            {
                serializer.SerializeObject(documentReference);
            }
            else
            {
                // should we throw if this is not a DocumentReference or just not do anything?
                throw new XpsSerializationException(SR.ReachSerialization_NoSerializer);
            }
        }
    };


    internal class DocumentReferenceCollectionSerializerContext :
                   ReachSerializerContext
    {
        public
        DocumentReferenceCollectionSerializerContext(
            ReachSerializerAsync        serializer,
            SerializableObjectContext   objectContext,
            IEnumerator                 enumerator,
            SerializerAction            action
            ):
            base(serializer,objectContext,action)
        {
            this._enumerator = enumerator;

View on GitHub (pinned to 81131a70a4)