简体   繁体   English

类型初始化异常

[英]Type initialization exception

I created imageHolder class: 我创建了imageHolder类:

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. 'Emgu.CV.CvInvoke'的类型初始值设定项引发了异常。

在此处输入图片说明

Here is Solution Explorer window: 这是“解决方案资源管理器”窗口:

在此处输入图片说明

Any idea why i get this exception and how can i fix it? 知道为什么我会收到此异常以及如何解决它吗?

Thank you in advance. 先感谢您。

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. 每当静态构造函数引发异常时,或者当您尝试访问该静态构造函数引发异常的类时,都会引发TypeInitializationException (您正在看到的异常)-它的InnerException属性是包含异常详细信息的属性实际上被抛出了-这是您需要调查的例外。

In this case from your screenshot the problem appears to be that the DLL "opencv_core240.dll" could not be found. 在这种情况下,您的屏幕快照出现的问题似乎是找不到DLL“ opencv_core240.dll”。 This could be for a number of reasons 这可能是由于多种原因

  • The DLL couldn't be found 找不到DLL
  • One of the dependencies of the DLL could not be found 找不到DLL的依赖项之一
  • The DLL was in the incorrect image format (32 bit as opposed to 64 bit) DLL的图片格式不正确(32位而不是64位)

I'd suggest that you take a look at this question to see if any of the suggestions on there help you. 我建议您看看这个问题 ,看看那里的任何建议是否对您有帮助。

VS项目属性页面

Checking this field did the trick for me. 检查此字段对我有用。 Under Project → Properties→ Build (Main/Startup project) 项目下 →属性→生成(主/启动项目)

我通过重新安装MSVCRT 9.0 SP1 x86解决了该问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM