dotnet/wpf · error · PrintingCanceledException
PrintingCanceledException
Error message
PrintingCanceledException
What it means
StartNewDocument calls IXpsOMPackageWriter.StartNewDocument through COM. Any COMException (invalid print ticket resource, part URI creation failure, writer already in a bad state, job cancelled) causes the policy to be invalidated and PrintingCanceledException to be thrown. This is the XpsOM path's uniform way of reporting that the print job can no longer proceed.
Solutions
- Validate the PrintTicket against the PrintQueue capabilities (queue.GetPrintCapabilities) before writing.
- Retry the entire print job; the policy is invalidated and cannot continue.
- Catch PrintingCanceledException and report the job as cancelled/failed to the user.
- Confirm the printer/driver is online and the spooler is healthy.
Example fix
// before
xpsWriter.Write(fixedDocSequence, printTicket); // throws PrintingCanceledException
// after
PrintQueue queue = ...;
PrintCapabilities caps = queue.GetPrintCapabilities(printTicket);
if (caps != null) { xpsWriter.Write(fixedDocSequence, printTicket); } // and catch PrintingCanceledException as job-cancel Defensive patterns
Strategy: try-catch
Validate before calling
var caps = printQueue.GetPrintCapabilities(printTicket); if (caps == null) throw new InvalidOperationException("PrintTicket incompatible with queue"); Type guard
static bool TicketValid(PrintQueue q, PrintTicket t) => q.GetPrintCapabilities(t) != null;
Try / catch
try { xpsWriter.Write(seq, ticket); }
catch (PrintingCanceledException) { NotifyUser("Job cancelled or printer unavailable; retry the job."); } Prevention
- Validate PrintTicket against queue capabilities before writing
- Monitor printer status during long jobs
- Retry the whole job rather than resuming an invalidated policy
- Keep drivers and spooler healthy
When it happens
Trigger: Serialization calling StartNewDocument for a new FixedDocument when the COM package writer rejects the call — malformed/null _currentDocumentPrintTicket, spooler failure, cancelled job, or invalid part URI.
Common situations: Printer goes offline between pages/documents; PrintTicket contains settings unsupported by the driver causing COM failure; job cancelled by user while document is being written.
Related errors
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/624809c50a037e26.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs:126
StartNewDocument()
{
try
{
Uri uri = _xpsManager.GenerateUniqueUri(XpsS0Markup.FixedDocumentContentType);
_currentFixedDocumentUri = uri;
IOpcPartUri partUri = GenerateIOpcPartUri(uri);
if (_currentDocumentPrintTicket == null)
{
_currentDocumentPrintTicket = new PrintTicket();
}
IXpsOMPrintTicketResource printTicketResource = GeneratePrintTicketResource(XpsS0Markup.FixedDocumentContentType, _currentDocumentPrintTicket);
_currentFixedDocumentSequenceWriter.StartNewDocument(partUri, printTicketResource, null, null, null);
_currentFixedDocumentWriterRef++;
}
catch (COMException)
{
Invalidate();
throw new PrintingCanceledException();
}
}
internal
void
ReleaseXpsOMWriterForFixedDocument()
{
if (_currentFixedDocumentWriterRef > 0)
{
_currentFixedDocumentWriterRef--;
if (_currentFixedDocumentWriterRef == 0)
{
_currentDocumentPrintTicket = null;
_currentFixedDocumentUri = null;
}
}
}View on GitHub (pinned to 81131a70a4)