1

I'm using .net framework 4.8 in my c# winforms project. Platform target Any CPU

In the project from the Manage NuGet Packages... I searched for Emgu.CV then in the project I added both using:

using Emgu.CV;
using Emgu.CV.Structure;

then inside a method I'm calling from a button call event:

private void Test(string videoPath)
{
    // Load the video file
    VideoCapture videoCapture = new VideoCapture(videoPath);
}

and

private void btnOpenVideo_Click(object sender, EventArgs e)
{
    Test(@"C:\Users\something\Downloads\test.mp4");
}

I can play the video file from the hard drive with any player.

But when clicking the button, it's throwing an exception on the line:

VideoCapture videoCapture = new VideoCapture(videoPath);

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

and

Inner Exception DllNotFoundException: Unable to load DLL 'cvextern': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

No clue how to fix it. I tried to google, but none of the answers worked so far.

Peter Macej
  • 4,831
  • 22
  • 49

1 Answers1

0

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

This exception is usually thrown when you install the Emgu CV Core library without installing the Emgu.Cv.runtime.windows library. In order for you to be able to use Emgu CV to process your videos then you need to install the Runtime.

  1. Open the Nuget package manager
  2. Click on the Browse tab and the search for Emgu.Cv.runtime.windows and install that dependency into your project
  3. Make sure you install a Runtime that is not greater than 4.4.x.x if your framework target is 4.8

After installing the Runtime then the exception should be resolved and the test functions should be called successfully.

Son of Man
  • 1,213
  • 2
  • 7
  • 27