i’m using the NuGet-Package of PDFTron-SDK for C#. I upgraded from 7.1.0.74119 to 9.0.2.77878 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 = "";
try
{
// 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);
}
else
{
// 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);
doc.Close();
}
}
// 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
System.AccessViolationException
HResult=0x80004003
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.>
Stapelüberwachung:
<Die Ausnahmestapelüberwachung kann nicht ausgewertet werden.>
<a href=“https://www.pdftron.com/documentation/core/info/prerequisites/windows#“prerequisites-for-cross-platform-(core)-pdf-library-with-windows””>Prerequisites - "Prerequisites for Cross-Platform (Core) PDF library with Windows"
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?
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.