PrintQueue.GetPrintCapabilities throws under several conditions.
System.Printing.PrintQueueException was unhandled
Message=PrintTicket provider failed to retrieve PrintCapabilities. Win32 error: -2147467259
at MS.Internal.Printing.Configuration.PTProvider.GetPrintCapabilities(MemoryStream printTicket)
at System.Printing.PrintTicketManager.GetPrintCapabilitiesAsXml(PrintTicket printTicket)
at System.Printing.PrintTicketManager.GetPrintCapabilities(PrintTicket printTicket)
at System.Printing.PrintQueue.GetPrintCapabilities(PrintTicket printTicket)
Here is the condition: in printer properties under Advanced tab you have to select incorrect driver. For example: you have Samsung 4228FN and in printer properties you select Samsung ML-3550 driver.
I don't really know how bad it is to change driver to incorrect one, however, in our company there are about 40 printers, almost 80% of them is configured incorrectly (incorrect driver) and this configuration works for years now - every single program prints correctly in all modes possible. So, obviously, the problem is in .NET.
When you fire queue.GetPrintCapabilities(queue.UserPrintTicket) it throws mentioned exception.
When you create a new ticket, copy each field from UserPrintTicket to a new one - everything works great.
When you use UserPrintTicket.Clone - method GetPrintCapabilities with cloned ticket throws.
This behavior is tested on WinXP and Win7, both with latest updates. Dudes from DevExpress also reproduced the bug and helped to isolate the issue from calls to their libraries.
The background behind this problem is that XPS writer uses UserPrintTicket to print WPF visual and it fails in scenarios with incorrect driver. There is a workaround - you can assign newly created ticket to the queue.UserPrintTicket property.