DLLimport unable to load dll

8

I am using an unmanaged dll in cpp which I call from from my C# web project. It works fine on my localhost but simply does not work on my shared hosting, winhost. It happens when I try to use one of the function in the dll.

The error message I am getting is:

"Unable to load DLL 'dllTest.dll': The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. (Exception from HRESULT: 0x800736B1)","errors":[{"name":"DllNotFoundException","message":"Unable to load DLL 'dllTest.dll': The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. (Exception from HRESULT: 0x800736B1)"}]}

I am suspecting that it is a path issue. The dll in question, dllTest.dll is placed in my bin folder. I am not sure where it is searching for the dll but is there a way I can specify a path for the search of the dll. I can't find a way to specify a relative path to the dll.

I do not think it is a dependency issue because my dllTest.dll is just a simple test and it only contains a simple add function.

Or could not be other causes?

Thanks for the help.

c#
c++
dll
interop
dllimport
asked on Stack Overflow Jul 16, 2011 by wayne • edited Aug 30, 2013 by Sir Crispalot

1 Answer

13

The problem is that your C++ DLL requires the CRT libraries to be installed in order to work. The bolded part of the error message is what gives you the hint:

Unable to load DLL 'dllTest.dll': The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.

That explains why everything is fine on your development machine—-they're already installed there because they got installed with your development tools—and why it doesn't work on the production server, which doesn't have the CRT redistributables installed.

You need to download the appropriate redistributable package for the version of Visual Studio that you compiled the DLL with. For example, if you're using Visual Studio 2010, you can download version 10 of the CRT redistributable here.

Alternatively, you could compile the DLL with the runtime libraries statically linked. To do that, change your project properties to throw the /MT switch instead of /MD—(it's found in the UI under "Configuration Properties" -> "C/C++" -> "Code Generation" -> "Runtime Library").

answered on Stack Overflow Jul 16, 2011 by Cody Gray

User contributions licensed under CC BY-SA 3.0