BadImageFormatException in c# - c#

I have downloaded tesseract from Here. When i tried to add the dll file to visual studio 2012, its showing error that its not an valid assembly. Can anyone suggest me some other dll file of ocr and sample coding. I've tried many websites but i dint found any good one. Then i found this dll file tessrect and used the following code
string path = #"C:\pic\mytext.jpg";
Bitmap image = new Bitmap(path);
Tesseract ocr = new Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "0123456789"); // If digit only
ocr.Init(#"C:\tessdata\", "eng", false); // To use correct tessdata
List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);
foreach (tessnet2.Word word in result)
Console.WriteLine("{0} : {1}", word.Confidence, word.Text);
But visual studio throwing error that its not valid assembly. can anyone help me in this ...
Edit : Error is
Could not load file or assembly 'tessnet2_64, Version=2.0.4.0, Culture=neutral, PublicKeyToken=1550524b5ba07e29' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Thanks n advance

The most common reason I've seen for this error is that the .NET app was built as X86 and you are including an x64 assembly, or vice versa.
Check the configuration manager in visual studio (Build menu) and what the assembly expects.
Update
According to this forum post the DLL you are using is an x86 assembly: https://code.google.com/p/tesseractdotnet/issues/detail?id=16 (unless they've created an x64 version since then)
In that case set your application to x86. If you don't have this available as yet, go into the Configuration Manager (Build menu), and set the Platform to x86. If it's not in the menu you can either edit the existing entries or create a new one by selecting that option in the drop down. If you select new: In the dialog, select the New Platform as x86 and copy the settings from what ever you were using currently.

In my case, this error occurred when I referenced a 32-bit project (DLL) in my 64-bit project.
It was necessary to change in the project configurations the target platform, to use preferably 32 bits:
Image:
When I checked the 32-bit preference, the problem was solved.

Related

How to embed or-tools in a C# application?

I'm trying to follow the instructions at https://developers.google.com/optimization/introduction/installing.html#windows_binary so that I can use or-tools inside my C# application.
I'm stuck on the make all step. I am in the Developer Command Prompt, but this command says:
'make' is not recognized as an internal or external command,
operable program or batch file.
I tried downloading GNU make, but that fails also. make install says "no target", and a bare make says:
process_begin: CreateProcess(NULL, cl /EHsc /MD /nologo /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS -nologo /O2 -DNDEBUG -DUSE_CBC -DUSE_CLP /D__WIN32__ /Iinclude\src\windows /DGFLAGS_DLL_DECL= /DGFLAGS_DLL_DECLARE_FLAG= /DGFLAGS_DLL_DEFINE_FLAG= /Iinclude /Iexamples -DUSE_GLOP -DUSE_BOP -c examples\cpp\costas_array.cc /Foobjs\costas_array.obj, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [objs\\costas_array.obj] Error 2
I also tried copying the DLLs from the bin folder directly into my project. I was able to compile against them by doing this, but when I tried to run it I got an error:
System.BadImageFormatException: 'Could not load file or assembly 'Google.OrTools, Version=5.1.6235.37215, Culture=neutral, PublicKeyToken=7a052e3db761d3be' or one of its dependencies. An attempt was made to load a program with an incorrect format.'
What am I missing?
Regarding the System.BadImageFormatException:
The OrTools binary format is provided in a 64bit dll.
Make sure, that your project is set to 64bit:
In Visual Studio you can check it out by right clicking on the Project --> Properties --> Build, Platform Target: This should be set to x64.
In case you have the same issue with web application, just enable 64 bits on IIS Express using Tools -> Options -> Projects and Solutions -> Web Projects -> Use the 64-bit version on IIS Express for web sites and projects
I was having this issue when using OR-Tools in a Web Application (it worked fine in a console application). I was getting:
System.BadImageFormatException HResult=0x8007000B Message=Could not load file or assembly 'Google.OrTools' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Using x64 didn't help, and Octopus was not building the project correctly either. The solution that worked for me was specifying which ASPNETCOMPILER to use (x64) in the project's .csproj :
<Project .... >
<PropertyGroup>
<AspNetToolPath>$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspNetToolPath>
</PropertyGroup>

sdk for morpho (safran) biometric scanner device

i have one safran device and its driver software. but i want to control it using c#. but i am unable to locate the SDK for this morpho biometric scanner. can anyone help me, so that i can make an home application with help of that.
i have tried with following code
using Morpho;
using MorphoAPI_1_0;
using MorphoSdkLiteDotNetWrapper;
Morpho.MorphoSmart.MorphoSmartDevice mSmtDev = new Morpho.MorphoSmart.MorphoSmartDevice();
but this give following error
Could not load file or assembly 'Morpho.MorphoSmart.dll' or one of its dependencies. The specified module could not be found.
You have to copy all of the dll file located in dll folder into the folder where your application will be released, according to your target machine architecture.
Ok, you should have two MorphoSmart libraries. One for x64, one for x86. I was using the x64 one in AnyCpu configuration and I was getting the same error. After switching to the x86 dll it worked fine (with AnyCpu configuration and a x64 operating system).

WebKit.NET with C# Project Runtime Exception

I have downloaded WebKit.NET 0.5-bin-cairo to work with an existing C# Project. I've included WebKitBrowser.dll and WebKit.Interop.dll as a reference to the module that requires it, as well as playing them directly in the debug/bin folder as directly by this tutorial.
I do not get any errors until I run the project and get an exception on this line in InitializeComponent() of the designer class.
this.webKitBrowser1 = new WebKit.WebKitBrowser();
The exception:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in WebKitBrowser.dll
Additional information: Failed to initialize activation context
I am building all the modules as 86x debug and my computer is 64 bit.
Any suggestions are appreciated as I've been playing around with this for multiple days.
I had encountered same issue. Three things were missing in my scenario.
manifest files: must be placed as all dlls are dynamically linked
VC++ must be installed on machine: In my case I used vc++2005 redistributable sp1.
Not only dlls/pdb/manifest you need to copy all the folders to root directory of executable
There is no correct packaging available yet for all files/folders of webkit.NET
And obviously project architecture should be x86 for all projects referencing webkit dlls
Have you tried:
WebKit.Net and OpenWebKitSharp Error: Failed to initialize activation context ? Namely to copy all the files from Core(not just the dlls) into your project /bin/release/ or /bin/debug/ folder?
quoted from the tutorial you followed:
Before we can run the application, WebKit.dll and it's dependencies must be present in the output directory. In Windows Explorer (or otherwise), copy all of the files from the WebKit .NET 'bin' directory to your project's output directory. For example, here is the listing of my output directory after copying:
D:\webkitdotnet\WebKitTest\WebKitTest\bin\Debug>ls
CFLite.dll icudt40.dll
JavaScriptCore.dll icuin40.dll
JavaScriptCore.resources icuuc40.dll
SQLite3.dll libcurl.dll
WebKit.Interop.dll libcurl.dll.manifest
WebKit.dll libeay32.dll
WebKit.resources libeay32.dll.manifest
WebKitBrowser.dll libpng13.dll
WebKitBrowser.dll.manifest libxml2.dll
WebKitBrowser.pdb libxslt.dll
WebKitTest.exe pthreadVC2.dll
WebKitTest.pdb ssleay32.dll
WebKitTest.vshost.exe ssleay32.dll.manifest
WebKitTest.vshost.exe.manifest zlib1.dll
curl.exe.manifest
You mentioned you only copied WebKitBrowser.dll and WebKit.Interop.dll over

Tessnet2 Could not load file or assembly 'tessnet2_64

Please dont mark -ve it is basic. Hi, In my visual studio2012 I am using tessnet2 library for ocr but unable to compile the code. I have seen
http://www.pixel-technology.com/freeware/tessnet2/
and have made all settings. I placed the tessdata folder in my .exe directory also. I have Microsoft visual c++ 2008 redistributable packages also (both x86 and x64) installed. My system is 64bit. I have also tried only using x64 package by deleting x86. I am using .net4.5 in my setting. I also tried other framework in my project settings. I have also tried x86orx64 or both in my project settings.
I have this code
Bitmap image = new Bitmap("C:\\Users\\Amna\\Documents\\text.tif");
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "0123456789"); // If digit only
ocr.Init(#"c:\temp", "fra", false); // To use correct tessdata
List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);
foreach (tessnet2.Word word in result)
Console.WriteLine("{0} : {1}", word.Confidence, word.Text);
but I get this error: Could not load file or assembly 'tessnet2_64, Version=2.0.4.0, Culture=neutral, PublicKeyToken=1550524b5ba07e29' or one of its dependencies. The system cannot find the file specified.
I have seen these links as well
Tessnet2 error in C#
IIS 7.5 Fixing An attempt was made to load a program with an incorrect format problem?
and many more.
Do you absolutely have to use the x64 version? I was having a lot of issue until I changed to using x86 version of the Tessnet2 (tessnet2_32.dll). I also changed my .NET framework target to 2.0. and making sure that the target platform is x86 architecture. I also had to make sure that I have the correct language data in tessdata folder where the program executable is. The data must also be a tesseract 2 data and not tesseract 3 data.

Unable to load DLL in C#

how to load a dll in a c# project
error:
Unable to load DLL 'Reader.dll': The specified module could not be
found. (Exception from HRESULT: 0x8007007E)
code sample:
[DllImport("Reader.dll")]
public static extern byte OpenReader(ref IntPtr hCom, byte LinkType, string com_port);
image:
If the problem is really "cannot be found", then using ProcMon from Sysinternals will show you where the system is looking for the DLL.
However, often these sort of exceptions mean 'I found the DLL but I can't load it', and that can be because a dependency of the DLL is missing rather than the DLL itself, or because the DLL is incompatible with the app trying to load it. If your C# app is set for 'Any CPU' and you're on a 64bit machine, you'll get this sort of error loading unmanaged 32-bit DLLs.
One way to isolate the problem would be to create a simple C/C++ project which loads the DLL. (Load it dynamically with LoadLibrary if you don't have access to the import lib.) Then use Dependency Walker to profile the test harness, and it will report the names of missing DLLs.
Although the reader.dll is unable to load GPSVC.dll and IESHIMS.DLL.
i managed to make it work by running the corflags command on application.exe
the application is now marked as 32bit:
corflags application.exe /32bit+
Version : v4.0.30319
CLR Header: 2.5
PE : PE32
CorFlags : 3
ILONLY : 1
32BIT : 1
Signed : 0
I found this in another post. Maybe it will help your situation
NUnit "missing" GPSVC.DLL on Windows 7/64
If it's a simple C DLL it just needs to be in the same folder as the .exe.
For me the solution was to installing the C++ Redistrable X64 on client machine.
(Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019.)
The dll was already on the right place, in the same folder than the .exe file.
Here you found the download link:
https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0

Categories