dotnet/wpf · error · XpsPackagingException
Current DocumentSequence, FixedDocument, or FixedPage not…
Error message
Current DocumentSequence, FixedDocument, or FixedPage not completed.
What it means
XpsFixedDocumentReaderWriter.AddFixedPage throws XpsPackagingException (ReachPackaging_PanelOrSequenceAlreadyOpen: 'Current DocumentSequence, FixedDocument, or FixedPage not completed.') when a page is already being written. The XPS writing model allows only one open page at a time; the previous page must be committed before a new one is added. The source guards on _currentPage != null.
Solutions
- Call Commit (and Close/dispose) on the current XpsFixedPageReaderWriter before calling AddFixedPage again.
- Ensure exception handlers commit or abandon the in-flight page so _currentPage is cleared.
- Wrap each page write in try/finally that disposes the page writer.
- Serialize page writing on one thread; do not call AddFixedPage concurrently.
Example fix
// before
for (var i = 0; i < pages; i++) { doc.AddFixedPage(); } // second call throws
// after
for (var i = 0; i < pages; i++) {
var page = doc.AddFixedPage();
try { WritePageContent(page); page.Commit(); }
finally { page.Close(); }
} Defensive patterns
Strategy: try-catch
Validate before calling
// only call when no page is open
if (currentPageWriter != null && !currentPageWriterCommitted)
return; // or commit first Try / catch
try { var page = doc.AddFixedPage(); /* write, commit */ }
catch (XpsPackagingException ex) when (ex.Message.Contains("not completed")) { /* commit outstanding page then retry */ } Prevention
- Always commit/close the previous page before AddFixedPage.
- Use using/try-finally around page writers.
- Never write pages from multiple threads.
When it happens
Trigger: Calling AddFixedPage while the XpsFixedPageReaderWriter returned by a previous AddFixedPage call is still active (its Commit/Close not yet called).
Common situations: Looped page-generation code that forgets to commit each page; exception paths that skip page commit leaving _currentPage set; concurrent writes from multiple threads.
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
- PrintTicket was already committed.
- ReachPackaging_OpenDocOrElementAlreadyCalled
- ReachPackaging_PrintTicketAlreadyCommitted
- SR.ReachSerialization_MustHaveSerializationManager
- " }} " element found. Expected fixed page element ( }} ).
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/4f461888e6b4de9d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs:418
/// </summary>
/// <returns>
/// Returns an interface to the newly created fixed page.
/// </returns>
/// <exception cref="ObjectDisposedException">The FixedDocument has already been disposed</exception>
/// <exception cref="SR.ReachPackaging_PanelOrSequenceAlreadyOpen">FixedPage is not completed.</exception>
public
IXpsFixedPageWriter
AddFixedPage(
)
{
ObjectDisposedException.ThrowIf(_metroPart is null || CurrentXpsManager.MetroPackage is null, typeof(XpsFixedDocumentReaderWriter));
//
// Only one page can be created/written at a time.
//
if (null != _currentPage)
{
throw new XpsPackagingException(SR.ReachPackaging_PanelOrSequenceAlreadyOpen);
}
_linkTargetStream = new List<String>();
//
// Create the part and writer
//
PackagePart metroPart = this.CurrentXpsManager.GenerateUniquePart(XpsS0Markup.FixedPageContentType);
XpsFixedPageReaderWriter fixedPage = new XpsFixedPageReaderWriter(CurrentXpsManager, this, metroPart, _linkTargetStream, _pagesWritten + 1);
//
// Make the new page the current page
//
_currentPage = fixedPage;
//Here we used to add the fixed page to _pageCache, but _pageCache is never accessed if this object was created as an IXpsFixedDocumentWriter.View on GitHub (pinned to 81131a70a4)