15

I created imageHolder class:

public class ImageHolder : Image<Bgr, Byte>
{   
    private String imagePath;

    public ImageHolder(String path):base(path)
    {
       this.imagePath = path;                     
    }   
    public String imgPathProperty
    {
        get
        { return imagePath; }
        set
        { imagePath = value; }
    }
}

I create instance of the class and initialize it,like this:

private ImageHolder originalImageHolder;
originalImageHolder = new ImageHolder(openFileDialog.FileName);

In runtime i get this exception:

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

enter image description here

Here is Solution Explorer window:

enter image description here

Any idea why i get this exception and how can i fix it?

Thank you in advance.

Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55
Michael
  • 13,950
  • 57
  • 145
  • 288
  • 2
    Looks like it can't find opencv_core240.dll; does that need to be in the same folder? – zimdanen Sep 14 '12 at 13:08
  • not exactly a duplicate of this (since there was no accepted answer)but maybe some of the information on [this other question](http://stackoverflow.com/questions/10930610/opencv-unmanaged-dlls-not-found-asp-net) and answers may work for you – Paolo Falabella Sep 14 '12 at 13:11
  • 1
    To reiterate and expand on what @zimdanen said, the InnerException text states that it was unable to load the DLL zimdanen mentions. See http://stackoverflow.com/questions/2066180/the-specified-module-could-not-be-found-0x8007007e for an explanation. – akton Sep 14 '12 at 13:15

3 Answers3

26

The TypeInitializationException (the exception that you are seeing) is thrown whenever a static constructor throws an exception, or whenever you attempt to access a class where the static constructor threw an exception - its InnerException property is the property that contains the detail of the exception that was actualy thrown - this is the exception that you need to investigate.

In this case from your screenshot the problem appears to be that the DLL "opencv_core240.dll" could not be found. This could be for a number of reasons

  • The DLL couldn't be found
  • One of the dependencies of the DLL could not be found
  • The DLL was in the incorrect image format (32 bit as opposed to 64 bit)

I'd suggest that you take a look at this question to see if any of the suggestions on there help you.

Community
  • 1
  • 1
Justin
  • 84,773
  • 49
  • 224
  • 367
2

VS Project Properties Page

Checking this field did the trick for me. Under Project→ Properties→ Build (Main/Startup project)

Community
  • 1
  • 1
SAm
  • 2,154
  • 28
  • 28
  • Yes - this fixed the issue for me too. Turns out the DLL my project requires can only be run in 32 bit! D'oh! – Mark Oct 09 '18 at 15:13
1

I solved the problem by reinstalling MSVCRT 9.0 SP1 x86

Michael
  • 13,950
  • 57
  • 145
  • 288