1
votes

I'm trying to use a 3rd party DLL (PDFExtract from 3-Heights) in my VB.NET project. The package comes with 2 .NET DLL's that I should add as references in the project as per the manual and a third native DLL that I need to add as an existing item to the project.

The help says:"The 3-Heights™ PDF Extract API does not provide a pure .NET solution. Instead, it consists of .NET assemblies, which are added to the project and a native DLL, which is called by the .NET assemblies. This has to be accounted for when installing and deploying the tool."

I followed the steps exactly but I get the following error when I try to initialize an object from the DLL: "An unhandled exception of type 'System.TypeInitializationException' occurred in MyProject.exe Additional information: The type initializer for 'Pdftools.PdfExtract.Document' threw an exception."

According to the help manual, this is an indication that windows cannot find the native DLL.

The downloaded package contains sample VB.NET project which surprisingly runs without a problem. I compared both projects and can't find anything different related to the problem. If I take that sample project as a starting point and then add my files on top of it and call my procedures, the code will work! There must be some setting or link that I'm missing in my project. Any idea?

My problem is that I want to create a DLL so I need a new class library project. Hence, I can't start from the sample project which is a Windows Form project.

My question is: are there any hidden settings or links to the DLL that could available in the sample project and not in mine? otherwise, what could be the reason for what I'm seeing?

1
I think you should change the Native DLLs property to Copy Always or Copy If Newer so that the linker copies the dll to your build path. Also better to set the compiler option to None. - bansi
If you clean your solution, and then rebuild, does the native dll get deployed along with their .net wrappers and your stuff? ie appears in bin/debug (or wherever you are building it to). - Tony Hopkinson
Actually it was set to Copy If Newer. I didn't understand what you meant by setting the compiler option to None but I went to the project properties, Compiler tab and compared both sample and my projects and found the difference: a check box labeled "Prefer 32-bit" was disabled and grayed out in the working sample project and was enabled in my project. I disabled it and everything worked fine! Many thanks for the inspiration. - Ahmad KFUPM

1 Answers

0
votes

Well, inspired by bansi, I reviewed the differences in the Compiler tab between both the sample project that works fine and my project that wasn't working and found the difference in a check box labeled "Prefer 32-bit". This was disabled and grayed out in the sample but was selected in my project (probably because the project was set to using .NET Framework 4 and mine 4.5 by default).

I unchecked the "Prefer 32-bit" checkbox and selected .NET framework 4 and then everything went cool! Not sure exactly why that was causing a problem but at least my project compiles and runs without errors now.

Thanks again bansi.