Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
When I debug my first C# windows form application with Emgucv, it debug quite well but when come to load picture, the type initializer for 'Emgu.CV.CvInvoke' threw an exception in the following sentence.

C#
//Load the Image
            Image My_Image = new Image(Openfile.FileName);

The type initializer for 'Emgu.CV.CvInvoke' threw an exception.

Can anyone help me? I'm using VS 2010 64-bits. Thanks.
Posted
Updated 4-Apr-18 12:33pm
v2
Comments
[no name] 24-Mar-12 6:50am    
And what was the exception that it threw?
Wendy2012 24-Mar-12 12:56pm    
Exception: Thrown: "An attempt was made to load a program with an incorrect format. (Exception from A System.BadImageFormatException was thrown: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) ) "

Try changing the compile mode to x86
 
Share this answer
 
Comments
Wendy2012 24-Mar-12 13:14pm    
My compile mode is x64 since im using 64 bit. Now it works out! Thanks.
harshali sonawane 24-Oct-13 5:41am    
type initializer for 'Emgu.CV.OCR.Tesseract' threw an exception
the same problem is here.
please give me the solution
Ahmed Elhelow 6-Dec-12 4:46am    
@Wendy2012
I have the same problem and have tried a lot of solutions but non of them works.
How does it work with you?
I try rebuilt it using opencv 2.3.1 library and it works!

Under Solution, choose Add Reference, then Add Existing Items of opencv_core231.dll and opencv_imgproc231.dll into project.

Thanks everyone.
 
Share this answer
 
At first, extract the details of the exception using try.. catch block as:

C#
try
{
   //Load the Image
   Image My_Image = new Image(Openfile.FileName);
}
catch (Exception ex)
{
   // ex.Message contains the details
}
 
Share this answer
 
Comments
Wendy2012 24-Mar-12 13:11pm    
Hi. I try it but seems like it does not display any image. Maybe need to edit.
jonathonburston 24-Mar-12 22:51pm    
Nice Answer.
this is giving me an error: "The type initializer for 'ADMS.Vehicle_Master' threw an exception". on click on treeview node.. the page is not opening

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
// try
//{
if (treeView1.SelectedNode.Text == "Vehicle Master")
{
Vehicle_Master vehicle = new Vehicle_Master();
vehicle.MdiParent = this;
vehicle.Show();
}
// }
//catch { }
}

please give a solution for it
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900