Emgu Could not found cvextern in IIS server

3

I'm having some issues running the Emgu on my server. It runs fine locally, but when I try to use it on the server with IIS, it doesnt work.

Here is the error:

System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'cvextern': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Emgu.CV.CvInvoke.RedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)\r\n   at Emgu.CV.CvInvoke..cctor()
   --- End of inner exception stack trace ---
   at Emgu.CV.CvInvoke.cvCreateImageHeader(Size size, IplDepth 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 VerifyID.Managers.ImageTreatmentsManager.ExtractDocumentFromImage(Bitmap bitmap)
   at VerifyID.VerifyWorker.ExecuteOCR(BigIdRequest request, BigIdEvent bigIdEvent)

I have the following dlls inside the x86 and x64:

  • concrt140.dll*
  • liblept172.dll*
  • msvcp140.dll*
  • vcruntime140.dll*
  • cvextern.dll*
  • libtesseract304.dll*
  • opencv_ffmpeg320.dll*

IIS version: 10.0

After copying the x64 dlls directly to the bin directory of the build the error changed to:

System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
   at Emgu.CV.CvInvoke.RedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)
   at Emgu.CV.CvInvoke..cctor()
   --- End of inner exception stack trace ---
   at Emgu.CV.CvInvoke.cvCreateImageHeader(Size size, IplDepth 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 VerifyID.Managers.ImageTreatmentsManager.ExtractDocumentFromImage(Bitmap bitmap)
   at VerifyID.VerifyWorker.ExecuteOCR(BigIdRequest request, BigIdEvent bigIdEvent)

Could someone help ?

c#
asp.net-mvc
iis
emgucv
asked on Stack Overflow Sep 12, 2017 by João Carvalho • edited Sep 12, 2017 by João Carvalho

1 Answer

4

I had this same problem, the application works perfectly on the local server (IIS Express used by the Visual Studio) but not on the remote Windows server, the solution that worked for me was:

(Please test your application between each step, maybe you don't need to do them all)

  1. In Visual Studio, open your application project properties and set the "Platform" to "Any CPU". Then publish your application to the remote server.

  2. Move all .dll files inside the x86 folder to the bin folder, pay special attention to the cvextern.dll, it must be inside the bin folder side by side with your application dll.

  3. Install Visual C++ Redistributable for Visual Studio on the remote server (just google it and you will find the download link. Please choose the download version according to your VS version, 2013, 2015, 2017, 2020, 2050...). Use the x86 installation even if you sever OS is x64.

  4. Activate your app_pool for the application for running 32 bit. https://help.webcontrolcenter.com/kb/a1114/how-to-enable-32-bit-application-pool-iis-7-dedicatedvps.aspx

  5. Go to the application \bin folder, grant the file security for the folder "x86" (which contains all the dll for emgu) as described in the following link "http://www.iis.net/learn/manage/configuring-security/application-pool-identities if your apppool being in used in defaulapppool, then you should add user "IIS AppPool\DefaultAppPool"

I really don't know why the x64 versions of those dlls are not working on the server for me. I still investigating it and as soon I find out why I will update this post.

Another solution (that is not elegant at all, but works) is to install the Visual Studio at the server, doing the same installation process that you have done for your development environment. By doing this you will have all dependencies and dlls needed (including the Visual C++) installed on the server.

Hope it helps!

answered on Stack Overflow Sep 25, 2017 by Rafael Adnet Pinho • edited Sep 25, 2017 by Rafael Adnet Pinho

User contributions licensed under CC BY-SA 3.0