3
votes

I have a program that uses Tesseract to extract text from images. I made a Native C++ DLL that is used in C# via P/Invoke. My C# application is a console x64 based and the DLL is also 64 bit.

After deploying to a Windows Server I receive an error that suggets the DLL (one I've made) does not exists. The error message is below.

System.DllNotFoundException: Unable to load DLL 'TesseractX64.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Utilities.Finance.PDFParser.PDF.OCRObject.GetUTF8Text(String path, String lang, String imgPath)

I know for sure that the DLL exists in that path. The TesseractX64.DLL is placed in the same folder as the C# application so it should work without any issues.

Here is my code:

[HandleProcessCorruptedStateExceptions]
[DllImport(@"TesseractX64.dll", EntryPoint = "GetUTF8Text", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr GetUTF8Text(string path, string lang, string imgPath);

What I have tried so far:

  1. Set the DLLImport path to a relative path for example C:\DLL\Tesseract.DLL. Still same issue.
  2. Installed Visual C++ 2005 - 2012 both x86 and x64. Still same issue.

It works perfectly fine on my Windows 7 x64 computer that I used to develop the program.

1
check if your based directory is the same where you start you application. - skalinkin
The message says unable to load. It doesn't necessarily mean that the .dll does not exist, but possibly that it can't be loaded because it depends itself on other .dll's that could not be found. - dxiv
@dxiv: Thanks for pointing that out. I will have a look. - JohnJackson

1 Answers

7
votes

Either:

  1. The DLL cannot be found, or
  2. One of the DLL's dependencies cannot be found.

Place the DLL in the same directory as the executable to ensure that it can be found.

Make sure that all the DLL's dependencies are met on each machine that needs to run your software. That will involve first working out what those dependencies are. The documentation for the DLL should tell you that information. Typically this means installing the MSVC runtime against which the DLL was linked.

You aren't allowed to redistribute the debug runtime. You'll want to make a release build of the native DLL even if the .NET code is in debug mode.