dotnet/wpf · error · XpsSerializationException
SR.ReachSerializationAsync_NoNgcType
Error message
SR.ReachSerializationAsync_NoNgcType
What it means
The NGCSerializerAsync constructor requires an NgcSerializationManagerAsync; the manager argument is first null-checked and then cast. If the manager is any other NgcBaseSerializationManager-derived type (not the async one), an XpsSerializationException with SR.ReachSerializationAsync_NoNgcType is thrown.
Solutions
- Pass an NgcSerializationManagerAsync instance to the NGCSerializerAsync constructor.
- If synchronous serialization is intended, use NGCSerializer with the matching synchronous manager instead.
- Add a compile-time or factory check so manager type and serializer type always correspond.
Example fix
// before var serializer = new NGCSerializerAsync(new NgcSerializationManager(stream, false)); // after var serializer = new NGCSerializerAsync(new NgcSerializationManagerAsync(stream, false));
Defensive patterns
Strategy: type-guard
Validate before calling
if (manager is not NgcSerializationManagerAsync asyncManager)
throw new ArgumentException("NGCSerializerAsync requires NgcSerializationManagerAsync"); Type guard
bool IsAsyncManager(NgcBaseSerializationManager m) => m is NgcSerializationManagerAsync;
Try / catch
try { var s = new NGCSerializerAsync(manager); }
catch (XpsSerializationException ex) {
// fall back to NGCSerializer for synchronous managers
} Prevention
- Pair each serializer type with its matching manager type in a factory method.
- Avoid mixing sync and async XPS APIs in the same pipeline.
- Null-check and type-check the manager before constructing the serializer.
When it happens
Trigger: Constructing new NGCSerializerAsync(manager) where manager is null or is a synchronous NgcSerializationManager (or other manager type) instead of NgcSerializationManagerAsync.
Common situations: Mixing sync and async XPS serialization APIs, e.g. passing a plain NgcSerializationManager to the async serializer after refactoring code from synchronous to asynchronous saving of XPS documents.
Related errors
- SR.Format(SR.MustBeOfType…
- SR.MustBeOfType
- SR.ReachSerialization_NotXpsSerializationManagerAsync
- SR.ReachSerialization_WrongPropertyTypeForFixedDocument
- SR.ReachSerialization_WrongPropertyTypeForFixedPage
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ea9ac8f2039056a8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializerAsync.cs:34
/// <summary>
/// Constructor for class ReachSerializer
/// </summary>
/// <param name="manager">
/// The serializtion manager, the services of which are
/// used later for the serialization process of the type.
/// </param>
public
NGCSerializerAsync(
PackageSerializationManager manager
)
{
ArgumentNullException.ThrowIfNull(manager);
_serializationManager = manager as NgcSerializationManagerAsync;
if(_serializationManager == null)
{
throw new XpsSerializationException(SR.ReachSerializationAsync_NoNgcType);
}
}
#endregion Constructor
#region Public Methods
public
virtual
void
AsyncOperation(
NGCSerializerContext context
)
{
if(context == null)
{
View on GitHub (pinned to 81131a70a4)