Error initializing iText PDF document when called from DLL via Catia, but not via exe

63 Views Asked by At

I have a DLL program that's invoked through Catia with the following snippet:

Sub CATMain()
    Dim myMainWindow As MyApp.Session
    Set myMainWindow = New MyApp.Session
    myMainWindow.CATIA = CATIA.Application
    myMainWindow.DisplayProgram
End Sub

I had registered the myApp DLL using "%windir%\Microsoft.NET\Framework64\v4.0.30319\Regasm.exe /codebase"

in myApp im using itext7 library for PDF manipulation and I have installed latest itext7 7.2.5. nuget package in my project.

when the program reaches the following line:

iText.Kernel.Pdf.PdfDocument pdfDoc = new iText.Kernel.Pdf.PdfDocument(reader, writer);

The error pops out: "the type initializer for 'itext.Commons.Actions.EventManager' threw an exception".

Interestingly, if I run the program via the exe file, it works fine. Can anyone help me understand why this error occurs when invoked through Catia but not when directly run from the exe?

EDIT: I have solved the problem by removing iText7 and related packages from the app.config file:

  <dependentAssembly>
    <assemblyIdentity name="itext.kernel" publicKeyToken="8354ae6d2174ddca" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-7.2.5.0" newVersion="7.2.5.0" />
  </dependentAssembly>

Why does the program run normally in Catia when the app.conf file is cleaned, but it doesn't when "dependentAssembly" is included??

Thank you!

0

There are 0 best solutions below