{"record":{"id":"44fd12b3f977584e","repo":"dotnet/wpf","slug":"printconfig-provider-pt2devmodefail","errorCode":"PrintConfig.Provider.PT2DevModeFail","errorMessage":"PrintConfig.Provider.PT2DevModeFail","messagePattern":"PrintConfig\\.Provider\\.PT2DevModeFail","errorType":"error_code","errorClass":"PrintQueueException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTProvider.cs","lineNumber":505,"sourceCode":"                if (umDevMode != IntPtr.Zero)\n                {\n                    UnsafeNativeMethods.PTReleaseMemory(new HandleRef(this, umDevMode));\n                    umDevMode = IntPtr.Zero;\n                }\n            }\n            \n            if ((hResult == (uint)NativeErrorCode.E_XML_INVALID) ||\n                (hResult == (uint)NativeErrorCode.E_PRINTTICKET_FORMAT))\n            {\n                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,\n                              \"{0} {1} {2}\",\n                              PrintSchemaTags.Framework.PrintTicketRoot,\n                              PTUtility.GetTextFromResource(\"FormatException.XMLNotWellFormed\"),\n                              errorMsg),\n                              nameof(printTicket));\n            }\n\n            throw new PrintQueueException((int)hResult,\n                                              \"PrintConfig.Provider.PT2DevModeFail\",\n                                              _deviceName,\n                                              errorMsg);\n        }\n\n        public override void Release()\n        {\n            if (_providerHandle != null)\n            {\n                _providerHandle.Dispose();\n                _providerHandle = null;\n                _deviceName = null;\n                _thread = null;\n            }\n        }\n\n        #endregion Public Methods\n","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTProvider.cs#L487-L523","documentation":"PTProvider.ConvertPrintTicketToDevMode failed to convert a PrintTicket into a Win32 DEVMODE structure via the print driver's native PT/PM conversion APIs. The provider wraps the native HRESULT in a PrintQueueException with code 'PrintConfig.Provider.PT2DevModeFail'. This usually means the ticket content is malformed or the driver rejected an option value.","triggerScenarios":"Calling PrintQueue.GetPrintCapabilities/ptProvider.ConvertPrintTicketToDevMode with a PrintTicket whose XML is not well-formed, or when the native IPrintTicketProvider::ConvertPrintTicketToDevMode call returns a failure HRESULT for the target device.","commonSituations":"Hand-crafted or deserialized PrintTicket XML with invalid schema content; printer drivers that don't fully implement PrintTicket conversion; driver replaced/updated so cached ticket no longer matches; passing a ticket from one queue to another device.","solutions":["Inspect errorMsg/_deviceName in the exception and validate the PrintTicket XML against the Print Schema before conversion.","Rebuild the PrintTicket from a fresh PrintQueue.DefaultPrintTicket or ticket XML from a known-good source instead of a stale/hand-edited one.","Verify the target driver is installed and functional (test printing from the OS); update or reinstall the printer driver.","Catch PrintQueueException and fall back to queue defaults."],"exampleFix":"// before\nvar devMode = ticket.GetXmlStream(); // hand-edited XML passed to conversion\n// after\nvar ticket = new PrintTicket(queue.GetPrintCapabilities().... ); // build from validated queue capabilities\nusing var xml = ticket.GetXmlStream(); // well-formed ticket generated by the API","handlingStrategy":"try-catch","validationCode":"if (ticket == null) throw new ArgumentNullException(nameof(ticket));\nusing var xml = ticket.GetXmlStream();\nif (xml == null || xml.Length == 0) throw new InvalidOperationException(\"PrintTicket XML is empty\");","typeGuard":null,"tryCatchPattern":"try\n{\n    queue.GetPrintCapabilities(ticket);\n}\ncatch (PrintQueueException ex) when (ex.Message.Contains(\"PT2DevModeFail\"))\n{\n    ticket = queue.DefaultPrintTicket; // fall back to driver defaults\n}","preventionTips":["Never hand-edit PrintTicket XML; always build tickets via the PrintTicket API","Test ticket conversion against the actual driver after driver updates","Don't reuse tickets across different printer queues"],"tags":["wpf","printing","printticket","devmode","native-interop"],"backgroundTag":"unsupported-operation","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"}