Type initialization exception

邮差的信 提交于 2019-12-17 19:34:09

问题


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.

Here is Solution Explorer window:

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

Thank you in advance.


回答1:


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.




回答2:


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




回答3:


I solved the problem by reinstalling MSVCRT 9.0 SP1 x86



来源:https://stackoverflow.com/questions/12425199/type-initialization-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!