dotnet/wpf · error · PrintJobException
PrintSystemException.PrintSystemJobInfo.XpsDocumentEvent
Error message
PrintSystemException.PrintSystemJobInfo.XpsDocumentEvent
What it means
A PrintSystemJobInfo code path that writes XPS document data to the spooler wraps a Win32 failure in PrintSystemJobInfo.CreatePrintJobException with key 'PrintSystemJobInfo.XpsDocumentEvent'. The HResult carries the native WritePrinter/spooler error.
Solutions
- Verify the job is still in the spooler (queue.GetPrintJobInfoCollection()) before writing job data.
- Ensure adequate free disk space for the spool folder on the print server.
- Retry the print operation end-to-end (create a new job) rather than reusing a possibly invalid job handle.
- Check the HResult to distinguish ERROR_DISK_FULL / ERROR_SPOOL_OFFLINE / invalid handle cases.
Example fix
// before
job.Write(buffer); // can throw PrintSystemException
// after
try { job.Write(buffer); }
catch (PrintSystemException ex)
{
// job handle may be invalid; recreate the job and reprint
job.Dispose();
throw new InvalidOperationException($"Job write failed (0x{ex.HResult:X8}); recreate the print job.", ex);
} Defensive patterns
Strategy: try-catch
Validate before calling
bool jobAlive = queue.GetPrintJobInfoCollection().Any(j => j.JobIdentifier == jobId);
if (!jobAlive) throw new InvalidOperationException("Job no longer in spooler; do not write to it"); Try / catch
try { job.Write(buffer); }
catch (PrintSystemException ex)
{
job.Dispose();
throw new InvalidOperationException($"XPS job event failed (0x{ex.HResult:X8}); recreate the job.", ex);
} Prevention
- Never reuse PrintSystemJobInfo handles after a failed write; recreate the job.
- Ensure adequate spool-folder disk space on the print server.
- Detect job removal/cancellation before streaming data.
- Log HResult values to distinguish offline spooler vs disk-full vs invalid handle.
When it happens
Trigger: Calling job/queue APIs that feed an XPS document event (e.g. writing job content, committing job-level changes) when the spooler rejects the write — job handle invalid, job already completed/cancelled, disk full on the spooler.
Common situations: Printing to a queue whose spool ran out of disk; job deleted by another process mid-write; XPS content stream larger than spooler limits; printer put offline during the write.
Related errors
- PrintSystemException.PrintSystemJobInfo.Create
- ArgumentException.NonNegativeValue (Parameter 'squareScale')
- ArgumentException.PositiveValue (Parameter 'value')
- ArgumentException.PositiveValue (Parameter 'value')
- errMsg (dynamic: message of caught…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f6c6617db65b40bc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintQueue.cpp:5246
{
XpsDocumentEventCancel();
break;
}
case XpsDocumentEventType::AddFixedPagePrintTicketPost:
case XpsDocumentEventType::AddFixedDocumentPrintTicketPost:
case XpsDocumentEventType::AddFixedDocumentSequencePrintTicketPost:
case XpsDocumentEventType::None:
default:
{
break;
}
}
}
}
catch(InternalPrintSystemException^ internalException)
{
throw PrintSystemJobInfo::CreatePrintJobException(internalException->HResult, "PrintSystemException.PrintSystemJobInfo.XpsDocumentEvent");
}
}
void
PrintQueue::
ForwardXpsFixedDocumentSequenceEvent(
System::Windows::Xps::Serialization::XpsSerializationXpsDriverDocEventArgs^ e
)
{
SafeHandle^ inputBufferSafeHandle = nullptr;
Int32 returnValue = DOCUMENTEVENT_UNSUPPORTED;
try
{
inputBufferSafeHandle = UnmanagedXpsDocEventBuilder::XpsDocEventFixedDocSequence(e->DocumentEvent,
writerStream->JobIdentifier,
(this->CurrentJobSettings->Description == nullptr) ?View on GitHub (pinned to 81131a70a4)