0

I have a simple C# 4.5.1 x64 application which calls unmanaged dlls via a /clr C++ wrapper. App runs fine on my development machine. If I copy to Windows Server 2008 or Windows Server 2012 (with Framework 4.5.1 installed) I get an error that the wrapper won't load.

I have installed DependencyWalker on the deployment machine and I get this:

LoadLibraryExW("MyWrapper.dll", 0x000.., LOAD_WITH_ALTERED_SEARCH_PATH) called from ...
Loaded "MyWrapper.dll" at ... Successfully hooked module.
Loaded "XX.dll" at ... Successfully hooked module. (Dependency for MyWrapper.dll)
Loaded "YY.dll" at ... Successfully hooked module. (Dependency for MyWrapper.dll)
Unloaded "MyWrapper.dll"
Unloaded "XX.dll"
Unloaded "YY.dll"
LoadLibraryExW("MyWrapper.dll", 0x000.., LOAD_WITH_ALTERED_SEARCH_PATH) returned null. The specified module cannot be found.

Does anyone know why everything is loaded then unloaded and then cannot be found?

phil
  • 57
  • 4
  • Are you sure, that runtime is installed on deployment machine? This might help http://stackoverflow.com/questions/9052694/visual-studio-2010-msvcr-dependency-removal – dousin Jan 07 '14 at 18:02
  • It looks like the wrapper did load, but after loading your app then went and unloaded them. Is there some other error happening? What's your code look like? – simon at rcl Jan 07 '14 at 18:15
  • @dousin .NET Framework runtime is definitely installed. – phil Jan 07 '14 at 20:23
  • @simon_at_rcl Not that I can see. I'm not calling LoadLibraryExW in my code - I just have a straight-forward .NET Reference to my wrapper. – phil Jan 07 '14 at 20:25
  • If you use unmanaged c++ dll, it links to a msvcr. It has nothing to do with .net. It is installed automatically with Visual Studio on the developer machine. You must redistribute it and install on the deployment machine together with your app. Google for vcredist.exe for your current Visual studio version. A copy of it resides also on the developer machine (in my case for vs2008: in %ProgramFiles%\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages) – dousin Jan 07 '14 at 23:03
  • If you build your unmanaged dll with a different compiler, there is probably another runtime required. Binaries from GCC from MinGW require libstdc++-6.dll and libgcc_s_dw2-1.dll. – dousin Jan 07 '14 at 23:07
  • Try to open your unmanaged dll (not the exe) with dependency walker and let us know, if there are missing dependencies – dousin Jan 07 '14 at 23:08
  • @dousin Thanks for your suggestions. 2008 redistributable was installed but I installed the one for 2013 anyway. App still didn't run. I opened my wrapper class in Dependency Walker (per your last suggestion) and it said msvcr100.dll was missing. Installed the 2010 redistributable and re-ran DW Profiler. Now says msvcr120d.dll is missing. This seems to be a debug non-redistributable so when I have a moment I'm going to try building a release version of my application and try again. – phil Jan 08 '14 at 12:43
  • @dousin It works! If you'd like to post your comment as the answer - i.e. make sure you have all the necessary redistributables installed and a release build I'll be very happy to mark as the answer. – phil Jan 08 '14 at 16:23

1 Answers1

2

Make sure you have all the necessary redistributables (vcredist.exe) installed and you deploy a release build.

Any unmanaged c/c++ dll and also c++/cli dll links to msvcr. It is automatically installed with Visual Studio on the developer machine. It must be installed on the deployment machine together with the app. Make sure to redistribute the correct vcredist.exe version which corresponds to your version (and service pack) of VS. For vs2008 it resides in %ProgramFiles%\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages). Note: Dependency walker does not show missing dll if it is loaded using LoadModule() or methods are loaded using [DllImport("Sample.dll")] in c#. In that case, open the unmanaged dll directly in Dependency walker and check missing deps. Make sure, unmanaged dll is in search path of your app.

dousin
  • 516
  • 1
  • 4
  • 10