开发者

DLLimport unable to load dll

开发者 https://www.devze.com 2023-03-20 13:47 出处:网络
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 t

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 oth开发者_StackOverflow社区er causes?

Thanks for the help.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号