{"record":{"id":"dc17d44c21316411","repo":"dotnet/wpf","slug":"printschematags-framework-printticketroot-ptutility-dc17d4","errorCode":null,"errorMessage":"PrintSchemaTags.Framework.PrintTicketRoot + PTUtility.GetTextFromResource(\"FormatException.XMLNotWellFormed\") + errorMsg","messagePattern":"PrintSchemaTags\\.Framework\\.PrintTicketRoot \\+ PTUtility\\.GetTextFromResource\\(\"FormatException\\.XMLNotWellFormed\"\\) \\+ errorMsg","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTProvider.cs","lineNumber":231,"sourceCode":"            IStream printCapabilitiesStream = CreateStreamOnHGlobal();\n            try\n            {\n                IStream printTicketStream = IStreamFromMemoryStream(printTicket);\n                try\n                {\n                    string errorMsg;\n                    // What happens if the native code returns a iStreamLength that is too long?\n                    // One option is we trust providers and don't do run-time check.\n                    uint hResult = UnsafeNativeMethods.PTGetPrintCapabilities(_providerHandle, printTicketStream, printCapabilitiesStream, out errorMsg);\n                    if (PTUtility.IsSuccessCode(hResult))\n                    {\n                        RewindIStream(printCapabilitiesStream);\n                        return MemoryStreamFromIStream(printCapabilitiesStream);\n                    }\n\n                    if (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                    else\n                    {\n                        throw new PrintQueueException((int)hResult,\n                                                      \"PrintConfig.Provider.GetPrintCapFail\",\n                                                      _deviceName,\n                                                      errorMsg);\n                    }\n                }\n                finally\n                {\n                    DeleteIStream(ref printTicketStream);\n                }","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTProvider.cs#L213-L249","documentation":"PTProvider.GetPrintCapabilities received E_PRINTTICKET_FORMAT from the native provider, meaning the supplied PrintTicket XML is invalid per the Print Schema. The API converts this into an ArgumentException whose message starts with the PrintTicket root element, the 'XML not well formed' resource text, and the provider's errorMsg, naming the printTicket parameter.","triggerScenarios":"Calling PTProvider.GetPrintCapabilities(printTicket) with a ticket the driver rejects as E_PRINTTICKET_FORMAT: schema-invalid element/attribute values, wrong namespace, or non-well-formed XML.","commonSituations":"Tickets produced by other applications with schema quirks; tickets serialized from streams with wrong position/encoding; editing ticket XML by hand and introducing invalid values (e.g. out-of-range PageCopies).","solutions":["Validate the PrintTicket against the Print Schema before calling (root element, namespace, allowed values).","Round-trip the ticket through System.Printing's PrintTicket class to normalize it.","Reset stream position and encoding before serialization.","Catch ArgumentException and regenerate a default ticket for the queue."],"exampleFix":"// before\ncaps = provider.GetPrintCapabilities(rawTicketStream); // schema-invalid ticket\n// after\nvar pt = new System.Printing.PrintTicket(rawTicketStream); // validates/normalizes\nrawTicketStream.Position = 0;\ncaps = provider.GetPrintCapabilities(rawTicketStream);","handlingStrategy":"validation","validationCode":"stream.Position = 0;\nvar pt = new System.Printing.PrintTicket(stream); // throws early if schema-invalid\nstream.Position = 0;","typeGuard":"static bool IsValidPrintTicket(Stream s)\n{\n    var pos = s.Position; s.Position = 0;\n    try { new System.Printing.PrintTicket(s); return true; }\n    catch { return false; }\n    finally { s.Position = pos; }\n}","tryCatchPattern":"try { caps = provider.GetPrintCapabilities(ticketStream); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"FormatException.XMLNotWellFormed\"))\n{\n    // regenerate default ticket via queue.DefaultPrintTicket\n}","preventionTips":["Round-trip tickets through System.Printing.PrintTicket to normalize before native calls.","Reset stream positions and fix encoding declarations.","Validate feature/option values against the driver's PrintCapabilities."],"tags":["wpf","printing","xml","print-schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}