Search code examples
c#opencvemgucv

Emgu CV unable to load DLL 'cvextern'


I've been trying to set up EmguCV in my C# project and I'm stuck. I've installed EmguCV, I've downloaded OpenCV and set up the bin folder to PATH. I've written the most basic lines of code:

using System;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;

string filepath = "...\\folder\\test.png";
Mat image = new Mat(filepath, ImreadModes.Color);
//some checks on this working out as expected

When I'm tyring to build the project, I receive the following:

Exception has occurred: CLR/System.TypeInitializationException
An unhandled exception of type 'System.TypeInitializationException' occurred in Emgu.CV.dll: 'The type initializer for 'Emgu.CV.MatInvoke' threw an exception.'
 Inner exceptions found, see $exception in variables window for more details.
 Innermost exception     System.DllNotFoundException : Unable to load DLL 'cvextern' or one of its dependencies: The specified module could not be found. (0x8007007E)
<Cannot evaluate the exception stack trace>

How can I solve this? It is my understanding that the issue is that cvextern.dll is not in the bin folder I've set up in PATH. But I downloaded opencv from their website so I doubt it's the wrong version either.

I'm using Visual Studio Code.


Solution

  • As mentioned in the comment, I just needed to run

    dotnet add package Emgu.CV.runtime.{etc}