1

I have this error that I can't fix and I reformatted this question after I got some testing done.

I have a code that works in my application if I am running the program with the same user I am logged as to windows:

PrintDialog printDialog = new PrintDialog();
printDialog.PrintDocument(((IDocumentPaginatorSource)flowDocument).DocumentPaginator,description);

However, when I try to run my application with a different account (for example elevate as an administrator or Run By Different User), my application crashes on this part of the code.

I get the following exception:

PrintTicket XML is not well-formed. Root element is missing.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)

I am not using XML files ( I think it's a break in the internal code not my code).

The object PrintDialog would have errors too in it as shown: errors

These (X)s show the moment I initiate the object ( new PrintDialog())

Also, I noticed that this exception wont happen if I build my program with Platform Target Any CPU or x64. However, I have to make i built as x86 for DLLS that I have.

What could be the issue?

Muhannad
  • 467
  • 4
  • 28
  • The instance constructor of `PrintDialog` is decorated with the `SecurityCriticalAttribute`. This means user elevation is not allowed for security reasons. Only the logged in user is allowed to open the dialog. – BionicCode Sep 15 '19 at 09:57
  • Thank you for you comment. Is there a reason the code works just fine with x64 or AnyCPU Plartform Target even with elevated user? – Muhannad Sep 15 '19 at 10:11
  • Just to clarify when I build my code with x64 or AnyCPU option selected the exception doesn't happen, but I must build it as x86 for DLLS that I have. – Muhannad Sep 15 '19 at 10:20

0 Answers0