I have a Visual Studio solution (all code in C#) that has the structure:
MySolution
|
+--MyLibrary (DLL library)
|
+--MyMVCSite (MVC 5 site)
|
+--MyConsoleApp (Console app)
MyLibrary references the Emgu.CV DLLs, which are a set of C# wrappers for the unmanaged library OpenCV. And I have all the OpenCV dlls being "Copy always" to the bin directory on building.
Now here is the issue. In MyConsoleApp, program.cs, I have the code:
MyLibrary mylib = new MyLibrary();
Image img = Image.FromFile(@"c:\\cat.jpg");
using (MemoryStream ms = new MemoryStream()) {
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
arr = ms.ToArray();
mylib.Process(arr);
}
which calls the MyLibrary code:
public void Process(byte[] buffer) {
PreprocessImage(buffer, true);
}
private Image<Gray, byte> PreprocessImage(byte[] buffer, bool resize) {
Image<Gray, byte> grayImage;
using (MemoryStream mss = new MemoryStream(buffer)) {
Bitmap bmpImage = (Bitmap)Image.FromStream(mss);
Image<Bgr, byte> img = new Image<Bgr, byte>(bmpImage); // <-- Emgu.CV type
// More processing on img
}
}
and everything succeeds. The variable img (which is built via Emgu.CVs wrapper functions to OpenCV) is set correctly and can be processed downstream, etc.
HOWEVER, when I try to repeat the exact same code from MyConsoleApp in the HomeController.cs of MyMVCSite using the code (in HomeController.cs), I get a runtime error on the line: Image<Bgr, byte> img = new Image<Bgr, byte>(bmpImage); stating {"Unable to load DLL 'opencv_core300': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"}
Both MyConsoleApp MyMVCSite reference MyLibrary, yet the console app works and the MVC app does not, despite using the same exact code to call MyLibrary. Does anyone have any idea what could be going on? I repeated this in a barebones project, and the behavior is still see the same thing.
UPDATE
I've posted my barebones project that shows this behavior at: https://github.com/brspurri/Test Still at a total loss here.