System.AccessViolationException when Converting MSG to PDF

Product: PDFNet SDK for C#

Product Version:


i’m using the NuGet-Package of PDFTron-SDK for C#. I upgraded from to and since the upgrade i always get “System.AccessviolationException” when i try to convert a msg-file.

Here’s the code i use:

            fehler = false;
            fehlermeldung = "";
            string outputFile = "";

                // Wo soll die optimierte PDF gespeichert werden?
                outputFile = Einstellungen.optimierungspfad + System.IO.Path.GetFileName(dateiMitPfad);
                outputFile = outputFile.Remove(outputFile.LastIndexOf("."));
                outputFile += "_from" + dateiendung + ".pdf";

                using (PDFDoc doc = new PDFDoc())
                    // Falls es sich um eine MSG-Datei handelt
                    // -> als erstes den Drucker setzen
                    if ((dateiendung == "msg" || dateiendung == "xls") && pdftron.PDF.Convert.Printer.IsInstalled("PDFTron Drucker"))
                        pdftron.PDF.Convert.Printer.SetPrinterName("PDFTron Drucker");
                        pdftron.PDF.Convert.ToPdf(doc, dateiMitPfad);
                        // Datei in PDF umwandeln
                        pdftron.PDF.Convert.OfficeToPDF(doc, dateiMitPfad, null);

                    // Und die Datei als linearisierte PDF speichern
                    doc.Save(outputFile, SDFDoc.SaveOptions.e_linearized);

            // TODO: Synchronisiert ins Memo schreiben
            catch(Exception ex)
                Funktionen.LogSchreiben(MethodInfo.GetCurrentMethod().Name, ex.Message);
                fehler = true;
                fehlermeldung = ex.Message;
                return "";

            return outputFile;

And the exception

  Nachricht = Es wurde versucht, im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein Hinweis darauf, dass anderer Speicher beschädigt ist.
  Quelle = <Die Ausnahmequelle kann nicht ausgewertet werden.>
<Die Ausnahmestapelüberwachung kann nicht ausgewertet werden.>



Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:


I suspect the issue is that you are using both a using statement block, and doc.Close() on the same PDFDoc instance.

Please remove the doc.Close() call and let us know how that works for you.

Hello Ryan,

i tried to remove the doc.Close(), but the error still appears. The exception is thrown at the following line:

pdftron.PDF.Convert.ToPdf(doc, dateiMitPfad);

Edit: I just figured out it seems to be a problem with x64 Build. When i change the Build-Target to x86 the conversion from msg-Files works fine.

Edit2: I read in the release-Notes, that for msg-Files Interop is used, am i right? Does this mean, that Microsoft Outlook (32bit) and PDF-Application(64bit) does not work together and so i have to compile my application in 32bit?
Is there an option to change the conversion back to using the printer?

Yes Interop is used, but Interop specifically should hide any implementation details, so a either end can be 32bit or 64bit (with Interop it could be a completely different operating system somewhere else in the world technically).

Note that Outlook only does part of the conversion, MSG → DOCX. Afterwards MS Word is used to convert the DOCX to PDF.

Is there an option to change the conversion back to using the printer?
No, Ideally we resolve the crash.

Does this issue occur with every MSG file you try?
Does it happen on other computers, or just one?
What version of Outlook and Word?
Are they licensed or in eval mode?
What .NET framework are you targetting?

Yes, it occurs on every MSG i test.

I tried it on three machines and it happened with all of them.

We are using Office Professional Plus 2019
Outlook Version 1808, Build 10340.20017
The same apply for Word
All Office-Programms are installed as 32-Bit-Version and they are also licensed.


Yes, it occurs on every MSG i test.

Is the issue then only with MSG files?
Are you able to convert DOCX? XLSX? PPTX?

Finally, do you have access to an older version of Office to test against?

Yes, the issue only occurs with MSG files. DOC(X), XLS(X) and PPT(X) are all working properly.

Unfortunately i have no access to an older Office-Version …

I am able to reproduce the issue, though not in debug mode, so it will take additional time to diagnose.

Thank you again for your assistance, and I will keep you posted on progress.

1 Like

Could you please try this developer preview build here:

Hello Ryan,

i just tried it and everything looks fine!

Great thanks for confirming. Tomorrow you can download a patched production build here.

Thank you!
Unfortunately your provided link doesn’t work. Is this Version also be published in NuGet?