charlesw / tesseract

A .Net wrapper for tesseract-ocr
Apache License 2.0
2.27k stars 741 forks source link

DllNotFoundException but libraries load :/ #405

Closed dulfe closed 6 years ago

dulfe commented 6 years ago

Hello,

I am trying to run a program using the branch Tesseract-4... it works fine in Dev but in the target machine it fails. (Dev: Win 10 Pro x64 / Prod: Win 2008 R2 x64)

System.DllNotFoundException: Failed to find library "libtesseract400.dll" for platform x86

Full Output


Tesseract Information: 0 : Test

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocati
on. ---> System.DllNotFoundException: Failed to find library "libtesseract400.dll" for platform x86.
   at InteropDotNet.LibraryLoader.LoadLibrary(String fileName, String platformName)
   at InteropRuntimeImplementer.TessApiSignaturesInstance.TessApiSignaturesImplementation..ctor(LibraryLoader loader)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, Cultu
reInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture,
 Object[] activationAttributes, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo cul
ture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at InteropDotNet.InteropRuntimeImplementer.CreateInstance[T]()
   at Tesseract.Interop.TessApi.Initialize()
   at Tesseract.Interop.TessApi.get_Native()
   at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode, IEnumerable`1 configFiles
, IDictionary`2 initialOptions, Boolean setOnlyNonDebugVariables)
   at Tesseract.TesseractEngine..ctor(String datapath, String language)
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\danie\source\repos\TesseractTest01\ConsoleApp1\ConsoleApp1\Pro
gram.cs:line 19

I read the ERROR 2 Wiki entry and all the other DllNotFound issues and I tried all these:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <system.diagnostics>
    <sources>
      <source name="Tesseract" switchValue="Verbose">
        <listeners>
          <clear />
          <add name="console" />
          <add name="file" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="console" type="System.Diagnostics.ConsoleTraceListener" />
      <add name="file"
         type="System.Diagnostics.TextWriterTraceListener"
         initializeData="c:\log\tesseract.log" />
    </sharedListeners>
    <trace autoflush="true">

    </trace>
  </system.diagnostics>
</configuration>

The program is very basic:

    class Program
    {
        private static readonly TraceSource trace = new TraceSource("Tesseract");

        static void Main(string[] args)
        {
            trace.TraceInformation("Test");

            var engine = new TesseractEngine("tessdata", "eng");
            Console.WriteLine($"Version: {engine.Version}");
            engine.Dispose();

        }
    }

So, Right now I am out of ideas... Am I forgetting anything?

Thank you. Daniel.

tdhintz commented 6 years ago

In Tesseract’s LibraryLoaderTraces.cs, line 12, I change this to “true” and run in a console command.

const bool printToConsole = false;

dulfe commented 6 years ago

@tdhintz Seems like that file was deleted in this branch... after reviewing the git history I found the code and applied it to this branch... with that I able to see the error messages:

...<removing successful messages>
Checking executing application domain location 'D:\OpenSource\dulfe\test' for 'libtesseract400.dll' on platform x64.
Trying to load native library "D:\OpenSource\dulfe\test\x64\libtesseract400.dll"...
Failed to load native library "D:\OpenSource\dulfe\test\x64\libtesseract400.dll".
Check windows event log.
Checking current application domain location 'D:\OpenSource\dulfe\test\' for 'libtesseract400.dll' on platform x64.
Trying to load native library "D:\OpenSource\dulfe\test\x64\libtesseract400.dll"...
Failed to load native library "D:\OpenSource\dulfe\test\x64\libtesseract400.dll".
Check windows event log.
No bin directory exists under the current application domain's location, skipping.
Checking working directory 'D:\OpenSource\dulfe\test' for 'libtesseract400.dll' on platform x64.
Trying to load native library "D:\OpenSource\dulfe\test\x64\libtesseract400.dll"...
Failed to load native library "D:\OpenSource\dulfe\test\x64\libtesseract400.dll".
Check windows event log.

Then I checked the event log and I found this:

Faulting application name: ConsoleApp1.exe, version: 1.0.0.0, time stamp: 0x5ad55553
Faulting module name: KERNELBASE.dll, version: 6.1.7601.23915, time stamp: 0x59b94f2a
Exception code: 0xe0434352
Fault offset: 0x000000000001a06d
Faulting process id: 0x8a0
Faulting application start time: 0x01d3d5f206890000
Faulting application path: D:\OpenSource\dulfe\test\ConsoleApp1.exe
Faulting module path: C:\Windows\system32\KERNELBASE.dll
Report Id: 47fe5a80-41e5-11e8-ae2d-00012e331ae2

I did some Google Search and nothing really help... I will try to create a VM and see if it fails there.

Any ideas would be appreciate it :)

Thank you.

tdhintz commented 6 years ago

Procmon says it finds the 2015 C++ Redistributable, but my recollection is that the 4.0 libs were built using the 2017 version.

dulfe commented 6 years ago

@tdhintz I tried installing 2017 and that did not work either.

I was able to create a VM with 2008 R2 and it worked... so something is wrong with the main server. I also used WinDbg to try and see what was wrong and seems like KernelBase.dll is just "the last one reporting the error" and not who is causing it.

WinDbg catches an "Illegal instruction"

ModLoad: 000007fe`e1740000 000007fe`e1745000   C:\Windows\system32\api-ms-win-crt-multibyte-l1-1-0.dll
(83c.88c): Illegal instruction - code c000001d (first chance)
ModLoad: 000007fe`dc7b0000 000007fe`dccc6000   D:\OpenSource\dulfe\TesseractTest01\x64\libtesseract400.dll

Well... I will reinstall that server (not many things in it)... that is quicker than trying to debug all dependencies.

Thank you!

tdhintz commented 6 years ago

Are the VMs on the same kind of processor? The builds likely target OpenMP and might take advantage of AVX2 or similar.

dulfe commented 6 years ago

@tdhintz No, they are not. They are both Intel but not the same family.

tdhintz commented 6 years ago

I just checked my builds. They have AXV2 specified for certain. That likely isn’t good for some processors.

dulfe commented 6 years ago

That is good to know!... that server is pretty old (that is why it is using Windows 2008 R2!), I will try and find out if it supports those extensions.

dulfe commented 6 years ago

I was wrong, that box uses AMD and as far as I know AVX2 is Intel. Do you think that is the cause?

dulfe commented 6 years ago

I was able to make it work.... after @tdhintz good point about AVX2, I decided to compile Tesseract directly from source (following their compilation instructions) making sure those extensions were disabled (which their are by default) and the program worked on that server (after fixing some file naming issues).

So... the Moral of the story is: If this lib fails, make sure your processor supports AVX2!

Thank you @tdhintz!

charlesw commented 6 years ago

Thanks for pointing that out @tdhintz. I'm thinking it'd probably be safest to distribute the native DLLs with these optimisations turned off. If in specific cases people want to use them they can provide their own DLLs.

Any thoughts?

On Fri., 20 Apr. 2018, 04:07 Daniel Ulfe, notifications@github.com wrote:

I was able to make it work.... after @tdhintz https://github.com/tdhintz good point about AVX2, I decided to compile Tesseract directly from source (following their compilation instructions) making sure those extensions were disabled (which their are by default) and the program worked on that server (after fixing some file naming issues).

So... the Moral of the story is: If this lib fails, make sure your processor supports AVX2!

Thank you @tdhintz https://github.com/tdhintz!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/charlesw/tesseract/issues/405#issuecomment-382829405, or mute the thread https://github.com/notifications/unsubscribe-auth/AAPzyPN-aN_R17AKF7-lC4Y9bA4OByL2ks5tqNJpgaJpZM4TXVgL .

tdhintz commented 6 years ago

Absolutely. People ask me for copies of the builds on a regular basis and I just uploaded what I had at the time for their convenience. I may have even disclosed the build settings in the Wiki, but I haven’t checked. I’m not inclined to worry about it until a decision is made to post a Nuget beta of 4.0. When that happens all new builds are needed anyway for both x86 and x64.