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

When compiled as an exe TesseractEngine won't initialize #609

Closed
AlexBaldwin42 opened this issue Apr 26, 2022 · 4 comments · May be fixed by #657
Closed

When compiled as an exe TesseractEngine won't initialize #609

AlexBaldwin42 opened this issue Apr 26, 2022 · 4 comments · May be fixed by #657

Comments

@AlexBaldwin42
Copy link

AlexBaldwin42 commented Apr 26, 2022

This is a .NET 6 console app. With Tesseract and Tesseract.Drawing Version 4.1.1
It will work when debugging and dotnet run
It will not work with -p:PublishSingleFile=true set but will run without it.
It will not work when I publish it as an exe using this.
dotnet publish --output "C:\" --runtime win-x64 --configuration Release -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true
It fails on
var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default))
The training data is in that folder it is the same folder the executable is being run.
I have tried using Directory.GetCurrentDirectory() as the path.
I have tried having the training data in the same folder as the executable with @"." path.
All these methods work when debugging but not when published as a single file executable.

 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
   at System.IO.Path.Combine(String , String )  
   at InteropDotNet.LibraryLoader.InternalLoadLibrary(String baseDirectory, String platformName, String fileName)   
   at InteropDotNet.LibraryLoader.CheckExecutingAssemblyDomain(String fileName, String platformName)  
   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 , Span1& , Signature , Boolean , Boolean )  
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo )  
   at System.RuntimeType.CreateInstanceImpl(BindingFlags , Binder , Object[] , CultureInfo )  
   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, IDictionary2 initialOptions, Boolean setOnlyNonDebugVariables)  
   at Program.<Main>$(String[] args) in C:\Users\alex\source\repos\PdfSplitter\Program.cs:line 26
[process exited with code 3762504530 (0xe0434352)]```
@benquan
Copy link

benquan commented Jul 22, 2022

I am having the same problem using .NET 6 and Windows Forms. Debugging works just fine but when publishing, it wont run. Did you manage to make it work?

This is my Error

Running
Running
Unexpected Error: Exception has been thrown by the target of an invocation.
Details:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
   at System.IO.Path.Combine(String path1, String path2)
   at InteropDotNet.LibraryLoader.InternalLoadLibrary(String baseDirectory, String platformName, String fileName)
   at InteropDotNet.LibraryLoader.CheckExecutingAssemblyDomain(String fileName, String platformName)
   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, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   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)
   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, IDictionary`2 initialOptions, Boolean setOnlyNonDebugVariables)
   at Tesseract.TesseractEngine..ctor(String datapath, String language, EngineMode engineMode)
   at TesseractTest.Form1.button1_Click(Object sender, EventArgs e)

@AlexBaldwin42
Copy link
Author

I got it to run by using
var engine = new TesseractEngine(@"//", "eng", EngineMode.Default))
while having the "tessdata" folder in the published directory.

@benquan
Copy link

benquan commented Aug 19, 2022

Didn't work for me

@gyfprivate
Copy link

https://github.com/gyfprivate/tesseract
I fix myself..

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

Successfully merging a pull request may close this issue.

3 participants