dotnet/wpf · error · XpsSerializationException
SR.ReachSerialization_NoFixedPageWriter
Error message
SR.ReachSerialization_NoFixedPageWriter
What it means
NullPackagingPolicy (used when serializing XPS directly to a print queue with no XPS package) throws this XpsSerializationException from AcquireResourceStreamForXpsFont when it needs to create a new font part but there is no current FixedPageWriter (_currentFixedPageWriter is null). The policy has no active page context to attach the font resource to, so serialization cannot continue. It signals that font acquisition was called outside of an active fixed-page write operation.
Solutions
- Ensure a FixedPage is being serialized (Begin/WriteFixedPage flow) before acquiring font resource streams, so _currentFixedPageWriter is set.
- Do not call AcquireResourceStreamForXpsFont after the current page's writer has been released; acquire all fonts within the page's serialization scope.
- If serializing to a file/package, use XpsPackagingPolicy instead of NullPackagingPolicy, which supports package parts independent of the print-pipeline path.
Example fix
// before: acquiring fonts outside page scope
xpsManager.PackagingPolicy.AcquireResourceStreamForXpsFont();
// after: acquire only during fixed-page serialization
serializer.WriteFixedPage(page => {
XpsResourceStream fs = policy.AcquireResourceStreamForXpsFont();
...
}); Defensive patterns
Strategy: validation
Validate before calling
// Acquire fonts only while a fixed page is being written
if (packagingPolicy is NullPackagingPolicy && !isInsideFixedPageWrite)
throw new InvalidOperationException("AcquireResourceStreamForXpsFont requires an active FixedPage writer"); Type guard
bool CanAcquireFont(NullPackagingPolicy p) => p.CurrentFixedPageWriter != null; // via reflection/internal access if available
Prevention
- Only acquire font streams inside the fixed-page serialization callback
- Never cache policy-acquired streams beyond the page lifetime
- Use XpsPackagingPolicy for file/package output
When it happens
Trigger: Calling AcquireResourceStreamForXpsFont() when _currentFixedPageWriter is null — i.e., before any FixedPage has begun writing or after the page writer was released (e.g., after ReleaseResourceStreamForXpsFont completed the page or a Commit/set of _currentFixedPageWriter=null occurred), while _currentXpsFontRef==0 forces creation of a new font part.
Common situations: Custom XpsSerializationManager/PackagingPolicy code that acquires font streams outside the normal page serialization flow; writing XPS directly to a print queue (null packaging) where page lifecycle ordering is wrong; misusing the serialization API after the current page finished.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Cannot find the appropriate serializer.
- Cannot find the appropriate serializer.
- Cannot find the appropriate serializer.
- Cannot instantiate a serializer of the given type.
- CurrentFixedPageWriter uninitialized
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/6350b59321e51887.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NullPackagingPolicy.cs:308
if(_currentXpsFontRef == 0)
{
//
// We need to create the corresponding part in the Xps package
// and then acquire the Stream
//
Stream fontStream = null;
if(_currentFixedPageWriter != null)
{
//
// Create a new Font Stream
//
fontStream = new MemoryStream();
}
else
{
throw new XpsSerializationException(SR.ReachSerialization_NoFixedPageWriter);
}
//
// retreive the appropriate stream and uri from the reach package api layer
//
if(fontStream !=null)
{
_fontResourceStream = new XpsResourceStream(fontStream,
new Uri("package/font",UriKind.Relative));
//
// This is to handle PSharp bug claiming we do not dispose
// this class. We can not dipose because ownership has been handed off.
// thus we set it to null
//
fontStream = null;
}
else
{View on GitHub (pinned to 81131a70a4)