Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DLLimport unable to load dll

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.

like image 719
wayne Avatar asked Jul 16 '11 08:07

wayne


People also ask

What does DllImport meaning in C#?

DllImport Attribute is a declarative tag used in C# to mark a class method as being defined in an external dynamic-link library (DLL) rather than in any . NET assembly.

How do I fix Hresult 0x8007007e problem?

If you are receiving this error message at the startup of the computer, place the computer in clean boot state and check if any third-party program is causing this issue. Putting your system in clean boot state helps in identifying if any third party applications or startup items are causing the issue.

How do I fix Dllnotfoundexception?

Simply, check pending updates, install them and/or restart Windows. After that frozen dll-s are freed and problems gone.


1 Answers

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").

like image 170
Cody Gray Avatar answered Sep 20 '22 04:09

Cody Gray