OpenCV Unmanaged DLLs not found asp.net

Arthur picture Arthur · Jun 7, 2012 · Viewed 9.2k times · Source

We are building a web application (C# .NET) that uses unmanaged libraries in the form of the Emgu opencv wrapper. We are forcing the build to be in 32-bit (x86), and we are using the 32-bit version of Emgu.

All this works nice on local builds, but when being published to our webserver the openCV Dll(s) fail to load:

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

System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'opencv_core240': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Emgu.CV.CvInvoke.cvRedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)
   at Emgu.CV.CvInvoke..cctor()
   --- End of inner exception stack trace ---
   at Emgu.CV.CvInvoke.cvCreateImageHeader(Size size, IPL_DEPTH depth, Int32 channels)
   at Emgu.CV.Image`2.AllocateData(Int32 rows, Int32 cols, Int32 numberOfChannels)
   at Emgu.CV.Image`2.set_Bitmap(Bitmap value)
   at Emgu.CV.Image`2..ctor(Bitmap bmp)

I tried the following things that I've found on stackoverflow and other sources:

  • Put the unmanaged Opencv Dll's in a seperate directory and put the path to this directory in the path environment variable, and restart the webservice.
  • Tested whether the server config allows for unmanaged code execution (yes)
  • Putting the unmanaged Opencv Dll's in system32\inetsrv and SysWOW64\inetsrv directories
  • Puting the unmanaged Opencv Dll's in a subdirectory 'x86' in the before mentioned folders

I understand this: http://msdn.microsoft.com/en-us/library/ms366723.aspx

is the reason of all trouble, however I do not understand why editing the path variable to include the correct path containing the Dll's doesn't solve anything.

Last useful post about this issue was in 2008, however no fool-proof solution has ben offered yet, so all the help is much appreciated!

Answer

user838914 picture user838914 · Jul 26, 2012

Make sure tbb.dll is also in the path, as opencv_core240.dll has a dependency on this. You can find tbb.dll under opencv/build/common/tbb.