dotnet/wpf · error · XpsSerializationException

SR.ReachSerialization_NoSerializer

Error message

SR.ReachSerialization_NoSerializer

What it means

SerializeDocumentReference throws this XpsSerializationException when the serializer manager cannot produce a serializer for an item inside the DocumentReference collection — i.e., an element retrieved from the enumerable is not a DocumentReference the serialization manager recognizes, so GetSerializerSuitableObject/serializer lookup fails. The code comments indicate the throw means the object is 'not a DocumentReference'.

Solutions

  1. Verify every element in the collection is a non-null, concrete DocumentReference before serializing.
  2. Ensure the standard DocumentReference serializer is registered with the SerializerManager (don't remove default ReachFramework serializer registrations).
  3. Filter or repair the collection (skip/replace null or foreign items) before passing it to serialization.

Example fix

// before: collection may contain foreign items
serializer.SerializeObject(dirtyReferences);

// after: sanitize first
var valid = dirtyReferences.Where(r => r is DocumentReference);
serializer.SerializeObject(valid);
Defensive patterns

Strategy: validation

Validate before calling

foreach (var r in references)
    if (r is not DocumentReference) throw new ArgumentException("Collection contains non-DocumentReference items");

Type guard

bool AllDocumentReferences(IEnumerable<object> items) => items.All(i => i is DocumentReference);

Try / catch

try { SerializeDocumentReferences(ctx); }
catch (XpsSerializationException ex) when (ex.Message.Contains("NoSerializer")) {
    // inspect collection element that has no serializer
}

Prevention

When it happens

Trigger: Iterating an IEnumerable<DocumentReference> whose element is null or of an unexpected type so the serializer lookup (SerializerManager.GetSerializerFor via the expression) yields no suitable serializer for the item.

Common situations: Custom collections typed as IEnumerable<DocumentReference> that actually contain nulls or derived/proxy objects the manager has no serializer for; mock or dynamic objects injected into the document reference collection during testing; broken serializer registration for DocumentReference.

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/f30c018227c97c9a. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentReferenceCollectionSerializer.cs:93

        /// <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);
            }
        }
    };
}

View on GitHub (pinned to 81131a70a4)