{"record":{"id":"f6c6617db65b40bc","repo":"dotnet/wpf","slug":"printsystemexception-printsystemjobinfo-xpsdocumentevent","errorCode":null,"errorMessage":"PrintSystemException.PrintSystemJobInfo.XpsDocumentEvent","messagePattern":"PrintSystemException\\.PrintSystemJobInfo\\.XpsDocumentEvent","errorType":"exception","errorClass":"PrintJobException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintQueue.cpp","lineNumber":5246,"sourceCode":"                {\n                    XpsDocumentEventCancel();\n\n                    break;\n                }\n                case XpsDocumentEventType::AddFixedPagePrintTicketPost:\n                case XpsDocumentEventType::AddFixedDocumentPrintTicketPost:\n                case XpsDocumentEventType::AddFixedDocumentSequencePrintTicketPost:\n                case XpsDocumentEventType::None:\n                default:\n                {\n                    break;\n                }\n            }\n        }\n    }\n    catch(InternalPrintSystemException^ internalException)\n    {\n        throw PrintSystemJobInfo::CreatePrintJobException(internalException->HResult, \"PrintSystemException.PrintSystemJobInfo.XpsDocumentEvent\");\n    }\n}\n\n\nvoid\nPrintQueue::\nForwardXpsFixedDocumentSequenceEvent(\n    System::Windows::Xps::Serialization::XpsSerializationXpsDriverDocEventArgs^    e\n    )\n{\n    SafeHandle^ inputBufferSafeHandle = nullptr;\n    Int32       returnValue           = DOCUMENTEVENT_UNSUPPORTED;\n\n    try\n    {\n        inputBufferSafeHandle = UnmanagedXpsDocEventBuilder::XpsDocEventFixedDocSequence(e->DocumentEvent,\n                                                                                         writerStream->JobIdentifier,\n                                                                                         (this->CurrentJobSettings->Description == nullptr) ?","sourceCodeStart":5228,"sourceCodeEnd":5264,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintQueue.cpp#L5228-L5264","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\njob.Write(buffer); // can throw PrintSystemException\n// after\ntry { job.Write(buffer); }\ncatch (PrintSystemException ex)\n{\n    // job handle may be invalid; recreate the job and reprint\n    job.Dispose();\n    throw new InvalidOperationException($\"Job write failed (0x{ex.HResult:X8}); recreate the print job.\", ex);\n}","handlingStrategy":"try-catch","validationCode":"bool jobAlive = queue.GetPrintJobInfoCollection().Any(j => j.JobIdentifier == jobId);\nif (!jobAlive) throw new InvalidOperationException(\"Job no longer in spooler; do not write to it\");","typeGuard":null,"tryCatchPattern":"try { job.Write(buffer); }\ncatch (PrintSystemException ex)\n{\n    job.Dispose();\n    throw new InvalidOperationException($\"XPS job event failed (0x{ex.HResult:X8}); recreate the job.\", ex);\n}","preventionTips":["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."],"tags":["printing","wpf","print-job"],"backgroundTag":"api-error-response","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}