Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

c# - Type initialization exception

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...