C# System.DllNotFoundException:无法在窗口 2003 上加载 DLL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2093485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 23:26:51  来源:igfitidea点击:

System.DllNotFoundException: Unable to load DLL on window 2003

c#dlldllnotfoundexception

提问by Rick

I have c++ dll using in my c# project, It ran fine on my window xp machine, but when i copy my debug project on window 2003 server (x64), i received error below, can any one tell me what is this problem, and how can i fix it.

我在我的 c# 项目中使用了 c++ dll,它在我的 windows xp 机器上运行良好,但是当我在 windows 2003 服务器(x64)上复制我的调试项目时,我收到以下错误,谁能告诉我这是什么问题,以及我该如何解决。

Thanks

谢谢

"System.DllNotFoundException: Unable to load DLL 'lib.dll': This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem"

“System.DllNotFoundException: Unable to load DLL 'lib.dll': This application has failed to start because the application configuration is不正确。重新安装应用程序可能会解决这个问题”

回答by Laurent Etiemble

For DLL loading problem, I suggest you to use the Dependency Walkertool. It has proved to be valuable when dealing with such problems as it will show you the exact problem.

对于 DLL 加载问题,我建议您使用Dependency Walker工具。事实证明,它在处理此类问题时很有价值,因为它会向您显示确切的问题。

If you own Visual Studio 2005, you can find it in C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\depends.exe.

如果您拥有 Visual Studio 2005,则可以在C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\depends.exe.

Update:

更新:

MSVCR90D.DLLis the debug version of the Visual C++ runtime 9.0. It should only be used for debugging purpose. I strongly suggest to build a release version of your library in order to avoid the DLL loading problem. However, if you absolutely need to deploy the debug version, you will find all the required DLLs in C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\Debug_NonRedist\x86.

MSVCR90D.DLL是 Visual C++ 运行时 9.0 的调试版本。它应该仅用于调试目的。我强烈建议为您的库构建一个发布版本,以避免 DLL 加载问题。但是,如果您绝对需要部署调试版本,您将在C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\Debug_NonRedist\x86.

回答by Hans Passant

It is complaining that it has trouble locating the CRT dlls. First check that the DLL contains the required manifest. In Visual Studio, File + Open + File, select the DLL and verify that it contains an RT_MANIFEST node. The next problem is that you can't deploy a debug build of your DLL. It will have a dependency on the debug version of the CRT, you can't get that installed on the target machine.

它抱怨找不到 CRT dll。首先检查 DLL 是否包含所需的清单。在 Visual Studio 中,文件 + 打开 + 文件,选择 DLL 并验证它是否包含 RT_MANIFEST 节点。下一个问题是您无法部署 DLL 的调试版本。它将依赖于 CRT 的调试版本,您无法在目标机器上安装它。

Either deploy the Release build of your DLL or compile the DLL with the /MT option so the CRT is statically linked. Project + Properties, C/C++, Code Generation, Runtime Library. This won't work if the DLL was compiled with the /clr option.

要么部署 DLL 的发布版本,要么使用 /MT 选项编译 DLL,以便静态链接 CRT。项目 + 属性、C/C++、代码生成、运行时库。如果 DLL 是使用 /clr 选项编译的,这将不起作用。

回答by Sam Holder

sounds like you have not installed the visual c++ runtime on the target machine. You can install that from hereAs it seems to be using the debug versions of those dlls perhaps you also need to build your app in release mode first? This postand this onehave some other suggestions that might help...

听起来您还没有在目标机器上安装 Visual C++ 运行时。您可以从这里安装它因为它似乎使用了这些 dll 的调试版本,也许您还需要先在发布模式下构建您的应用程序? 这篇文章这篇文章还有一些其他建议可能会有所帮助...

回答by wj32

Is lib.dll a 32-bit DLL? Your C# program will run on x64 natively but will be unable to load 32-bit DLLs. You can try changing the target CPU of the C# project to "x86" to force it to run under WOW64.

lib.dll 是 32 位 DLL 吗?您的 C# 程序将在本机 x64 上运行,但将无法加载 32 位 DLL。您可以尝试将 C# 项目的目标 CPU 更改为“x86”,以强制其在 WOW64 下运行。