dotnet/wpf · error · ArgumentException
PrintSchemaTags.Framework.PrintTicketRoot +…
Error message
PrintSchemaTags.Framework.PrintTicketRoot + PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed") + xmlException.Message What it means
GetPrintCapabilities received a PrintTicket whose XML failed to parse (XmlException) while wrapping it in an InternalPrintTicket. The API surfaces this as an ArgumentException whose message starts with the PrintTicket root element name followed by the 'XML not well formed' resource text and the parser's message.
Solutions
- Validate the PrintTicket XML is well formed (parse it with XmlDocument/XDocument) before calling GetPrintCapabilities.
- Reset the stream position to 0 before passing a MemoryStream to the API.
- Ensure the root element is PrintTicket from the print schema namespace and the XML declaration matches the actual encoding.
- Catch ArgumentException around GetPrintCapabilities and inspect the message for the underlying XmlException detail.
Example fix
// before stream.Position = 0; // often forgotten caps = provider.GetPrintCapabilities(printTicket); // after stream.Position = 0; new XDocument(XDocument.Load(stream)) ; // throws early with a clear parser message stream.Position = 0; caps = provider.GetPrintCapabilities(printTicket);
Defensive patterns
Strategy: validation
Validate before calling
stream.Position = 0;
try { new XDocument(XDocument.Load(stream, LoadOptions.None)); }
catch (XmlException ex) { throw new InvalidOperationException("PrintTicket XML is not well formed: " + ex.Message, ex); }
finally { stream.Position = 0; } Type guard
static bool IsWellFormedXml(Stream s)
{
var pos = s.Position; s.Position = 0;
try { XDocument.Load(s); return true; }
catch (XmlException) { return false; }
finally { s.Position = pos; }
} Try / catch
try { caps = provider.GetPrintCapabilities(printTicket); }
catch (ArgumentException ex) when (ex.Message.Contains("not well formed"))
{
// regenerate a default ticket for the queue
} Prevention
- Always reset Stream.Position to 0 before passing ticket streams.
- Validate ticket XML well-formedness with XDocument.Load before use.
- Never hand-edit PrintTicket XML without re-parsing it afterwards.
When it happens
Trigger: Calling FallbackPTProvider.GetPrintCapabilities(printTicket) with a printTicket MemoryStream/XmlReader containing malformed XML (bad encoding, unclosed tags, invalid characters), so new InternalPrintTicket(printTicket) throws XmlException.
Common situations: Hand-edited or template-generated PrintTicket XML; stream position not reset before passing to the API; wrong encoding declaration; truncated ticket saved to a stream.
Related errors
- errMsg (dynamic: message of caught…
- PrintSchemaTags.Framework.PrintTicketRoot +…
- " }} " element found. Expected fixed page element ( }} ).
- ArgumentException.NonNegativeValue (Parameter 'squareScale')
- ArgumentException.PositiveValue (Parameter 'value')
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a48760a0bd942437.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs:108
/// </exception>
/// <exception cref="ArgumentException">
/// The input PrintTicket specified by <paramref name="printTicket"/> is not well-formed.
/// </exception>
/// <exception cref="PrintQueueException">
/// The PTProvider instance failed to retrieve the PrintCapabilities.
/// </exception>
public override MemoryStream GetPrintCapabilities(MemoryStream printTicket)
{
VerifyAccess();
InternalPrintTicket internalTicket = null;
try
{
internalTicket = (printTicket != null) ? new InternalPrintTicket(printTicket) : null;
}
catch (XmlException xmlException)
{
throw new ArgumentException(
String.Format(
CultureInfo.CurrentCulture,
"{0} {1} {2}",
PrintSchemaTags.Framework.PrintTicketRoot,
PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"),
xmlException.Message),
nameof(printTicket),
xmlException);
}
DevMode defaultDevMode = GetDEVMODE(BaseDevModeType.UserDefault);
DevMode devMode = defaultDevMode.Clone();
PrintTicketToDevMode(devMode, internalTicket, PrintTicketScope.JobScope, DevModeFields.All);
MemoryStream capabilitiesStream = new MemoryStream();
WinSpoolPrinterCapabilities capabilities = GetCapabilities(devMode);View on GitHub (pinned to 81131a70a4)