1

I have a problem that I dont understand how to fix it. Specially I work at project (C#,VB 2015) with orders, receipts etc and when I run at debug mode everything works great. But when I made a setup of my project and run my application this error appeared:

System.FormatException: PrintTicket XML is not well-formed. Root element is missing. ---> System.Xml.XmlException: Root element is missing.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.Load(Stream inStream)
   at MS.Internal.Printing.Configuration.InternalPrintTicket..ctor(Stream xmlStream)
   --- End of inner exception stack trace ---
   at MS.Internal.Printing.Configuration.InternalPrintTicket..ctor(Stream xmlStream)
   at System.Printing.PrintTicket..ctor(Stream xmlStream)
   at System.Printing.Interop.PrintTicketConverter.InternalConvertDevModeToPrintTicket(PTProviderBase provider, Byte[] devMode, PrintTicketScope scope)
   at System.Printing.PrintTicketManager.ConvertDevModeToPrintTicket(Byte[] devMode)
   at System.Printing.PrintQueue.get_UserPrintTicket()
   at Simple.Printing.PrintService.PrintOrder(IEnumerable`1 templates, Order order, Shift shift, IList`1 printingPosts, SimpleConfiguration configuration, Boolean showPrices, Invoice invoice, Boolean skipPosts, Int32 postPosition)
   at Simple.Domain.Services.OrderService.<>c__DisplayClass3c.<PrintOrder>b__39()

and I cant print my order. The code where my program is crushed is that :

var printer = dialog.PrintQueue;
var ticket = printer.UserPrintTicket ?? printer.DefaultPrintTicket;
var capabilities = printer.GetPrintCapabilities(ticket);
ticket.CopyCount = post.Copies > 0 ? post.Copies : ticket.CopyCount;
1ac0
  • 2,875
  • 3
  • 33
  • 47
  • I need to see sample of xml file. This looks similar to previous posting where I responded with a good solution : https://stackoverflow.com/questions/46220779/c-sharp-read-xml-file-not-correctly-formatted/46221333#comment79463888_46221333 – jdweng Sep 19 '17 at 09:17
  • 1
    i dont use any of xml file.i just create a printticket and then print a xml class like this: OrderKitchen2 receipt = new OrderKitchen2(model); Visual visual = (UIElement)receipt.FindName("visual"); var stackpanel = (StackPanel)visual; stackpanel.Measure ... stackpanel.Arrange .. var paginator = new VisualPaginator(visual as FrameworkElement); paginator.PageSize = ... paginator.PrinterMargins = ... dialog.PrintDocument(paginator); – Giannis Tsilafakis Sep 19 '17 at 09:36
  • Not true. The code is either parsing an xml string or reading an xml file. I need to see the xml to seolve issue. I think the GetPrintCapabilities() is returning an xml string, or ticket is not valid. – jdweng Sep 19 '17 at 10:07
  • Same problem here. The XML Exception happens inside the .NET Framework and not inside my code. – andreas Jun 18 '18 at 11:23
  • @GiannisTsilafakis: Did you have this error only on one specific printer? For us it only seems to happen on one specific POS Thermal Printer – andreas Jun 18 '18 at 11:31

0 Answers0