dotnet/wpf · error · ArgumentException

PrintSchemaTags.Framework.PrintTicketRoot +…

Error message

PrintSchemaTags.Framework.PrintTicketRoot + PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed") + errorMsg

What it means

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.

Solutions

  1. Validate the PrintTicket against the Print Schema before calling (root element, namespace, allowed values).
  2. Round-trip the ticket through System.Printing's PrintTicket class to normalize it.
  3. Reset stream position and encoding before serialization.
  4. Catch ArgumentException and regenerate a default ticket for the queue.

Example fix

// before
caps = provider.GetPrintCapabilities(rawTicketStream); // schema-invalid ticket
// after
var pt = new System.Printing.PrintTicket(rawTicketStream); // validates/normalizes
rawTicketStream.Position = 0;
caps = provider.GetPrintCapabilities(rawTicketStream);
Defensive patterns

Strategy: validation

Validate before calling

stream.Position = 0;
var pt = new System.Printing.PrintTicket(stream); // throws early if schema-invalid
stream.Position = 0;

Type guard

static bool IsValidPrintTicket(Stream s)
{
    var pos = s.Position; s.Position = 0;
    try { new System.Printing.PrintTicket(s); return true; }
    catch { return false; }
    finally { s.Position = pos; }
}

Try / catch

try { caps = provider.GetPrintCapabilities(ticketStream); }
catch (ArgumentException ex) when (ex.Message.Contains("FormatException.XMLNotWellFormed"))
{
    // regenerate default ticket via queue.DefaultPrintTicket
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/dc17d44c21316411. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTProvider.cs:231

            IStream printCapabilitiesStream = CreateStreamOnHGlobal();
            try
            {
                IStream printTicketStream = IStreamFromMemoryStream(printTicket);
                try
                {
                    string errorMsg;
                    // What happens if the native code returns a iStreamLength that is too long?
                    // One option is we trust providers and don't do run-time check.
                    uint hResult = UnsafeNativeMethods.PTGetPrintCapabilities(_providerHandle, printTicketStream, printCapabilitiesStream, out errorMsg);
                    if (PTUtility.IsSuccessCode(hResult))
                    {
                        RewindIStream(printCapabilitiesStream);
                        return MemoryStreamFromIStream(printCapabilitiesStream);
                    }

                    if (hResult == (uint)NativeErrorCode.E_PRINTTICKET_FORMAT)
                    {
                        throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                      "{0} {1} {2}",
                                      PrintSchemaTags.Framework.PrintTicketRoot,
                                      PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"),
                                      errorMsg),
                                      nameof(printTicket));
                    }
                    else
                    {
                        throw new PrintQueueException((int)hResult,
                                                      "PrintConfig.Provider.GetPrintCapFail",
                                                      _deviceName,
                                                      errorMsg);
                    }
                }
                finally
                {
                    DeleteIStream(ref printTicketStream);
                }

View on GitHub (pinned to 81131a70a4)