Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyNotFoundException when running sample #141

Closed
CapCap opened this issue Dec 1, 2014 · 6 comments
Closed

KeyNotFoundException when running sample #141

CapCap opened this issue Dec 1, 2014 · 6 comments
Labels

Comments

@CapCap
Copy link

CapCap commented Dec 1, 2014

using(var engine = new TesseractEngine( "./tessdata", "eng", EngineMode.Default ))
causes error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictio
nary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at InteropDotNet.LibraryLoader.LoadLibrary(String fileName, String platformName)
   at InteropRuntimeImplementer.LeptonicaApiSignaturesInstance.LeptonicaApiSignaturesImplementation..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, CultureInfo 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 culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at InteropDotNet.InteropRuntimeImplementer.CreateInstance[T]()
   at Tesseract.Interop.LeptonicaApi.Initialize()
   at Tesseract.Interop.TessApi.Initialize()
   at Tesseract.Interop.TessApi.get_Native()
   at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode, IEnumerable`1 configFiles)
   at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode)
   at EDMarketOCR.Program.Main(String[] args) in c:\Users\NoOne\Desktop\ED\EDMarketOCR\EDMarketOCR\Program.cs:line 60
Unexpected Error: Exception has been thrown by the target of an invocation.
@charlesw
Copy link
Owner

charlesw commented Dec 7, 2014

Thanks for the bug report, will be fixed in the next release.

Note: That this was occurring because it failed to find the dlls might be worth turning on tracing for the 'Tesseract' source to work out where it's looking:

<system.diagnostics>
    <sources>
      <source name="Tesseract" switchValue="Information">
        <listeners>
          <add name="configConsoleListener" type="System.Diagnostics.ConsoleTraceListener" />
        </listeners>
      </source>
    </sources>
</system.diagnostics>

As the 'fix' just throws a more explicit error it won't resolve the underlying issue.

@lreading
Copy link

I'm experiencing the same exception with the same line of code.

There is an inner Exception that says "The given key was not present in the dictionary."

I did not have this problem when I used the nuget package in a WCF application project, but when I created a class library then referenced the class library from a different WCF project it started happening.

Hopefully that helps, and thank you for maintaining this code! Please let me know if there's anything I can do to help.

@xcud
Copy link

xcud commented Jan 27, 2015

I ran into this when distributing a class library to a fresh machine. I turned on verbose logging to discover that the library it was unable to load was the MS Visual C++ Redistributable. Installing this resolved the issue: http://www.microsoft.com/en-us/download/details.aspx?id=30679#

@lreading
Copy link

I'll double check to make sure I have the C++ redistributables installed tomorrow.

I was using the same machine the entire time... Interesting that it works in the WCF service and not the class library.... I will update tomorrow, thank you!!

@xcud
Copy link

xcud commented Jan 27, 2015

Grab the dependency walker (http://www.dependencywalker.com/) and use that to open up the lib files in the platform (x86 or x64 depending on your machine). That'll tell you if a dependency, MSVCRT*.dll or something else, is missing.

@charlesw
Copy link
Owner

Also double check the native tesseract dlls (x86 and x64) are being
distributed. If your taking a reference on a class library these may NOT be
being copied to your program's bin file.

On Tue, Jan 27, 2015 at 2:49 PM, Leo [email protected] wrote:

I'll double check to make sure I have the C++ redistributables installed
tomorrow.

I was using the same machine the entire time... Interesting that it works
in the WCF service and not the class library.... I will update tomorrow,
thank you!!


Reply to this email directly or view it on GitHub
#141 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants