c# - System.DllNotFoundException : Unable to load DLL. 开发机器没有错误但目标机器有错误

标签 c# windows dll

我在 Visual Studio 2012 上使用 WPF 构建了一个 C# 应用程序,该应用程序使用 C++ DLL 并面向 .NET4.5。我有两个项目正在运行,一个用于 C# 项目,另一个用于 C++ DLL 项目。我将这两个项目发布到一个文件夹中,该文件夹中有一个用于 C# 的 .exe 和一个用于 C++ 的 .dll

我在开发它们的机器上运行它们,一切正常。我在其他机器上运行 .exe 并抛出此异常:

System.DllNotFoundException: Unable to load DLL

无法识别同一文件夹中的 DLL。

我尝试了很多东西,但似乎没有任何效果。我遵循了 this post 中的解决方案但没有任何效果。

Dev 和 Target 机器是相同的。在 Dev 中,安装了 Visual Studio 2012,但这是唯一的区别。

代码:

C#:

[DllImport(@"Wireless.dll", EntryPoint = "?cert_exists@certificate@CertFuncs@@SAHHPBD@Z", CallingConvention = CallingConvention.Cdecl)]
    static extern int cert_exists(int store, [MarshalAs(UnmanagedType.LPTStr)]string cert_str);

C++:

static int __declspec(dllexport) cert_exists(int type, LPCSTR cert_str);

更新:

如果我在目标机器上安装 Visual Studio 2012,一切正常。如果我删除它,应用程序会再次崩溃。关于 VS 正在添加什么可以使应用程序工作的任何想法?

最佳答案

只是一个猜测:在用户的机器上安装 Microsoft Visual C++ 2012 Redistributable Package。您使用的 native DLL 可能有其他必须安装的依赖项(尝试 Dependency Walker )。如果 native DLL 需要例如注册表设置、配置文件等,这些也应该存在。它应该像在开发机器上安装它一样分发给用户机器。

关于c# - System.DllNotFoundException : Unable to load DLL. 开发机器没有错误但目标机器有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14587775/

相关文章:

c++ - 是否有可能在 Windows 上防止其他应用程序 Hook 系统 DLL

python - 在 Windows 上使用 Python 将 SVG 转换为 PNG

Windows Azure : Creation of a file on cloud blob container

dll - g++:无法识别的选项 '-static-libstdc++'

c# - 如何卸载动态加载的 DLL

python - DLL加载失败: The specified module could not be found [Python]

c# - 如何将一个静态列表的项目转移到另一个

在 citrix session 中运行时,C# 用于确定客户端 ip 地址?

c# - Ajax.BeginForm() 带有复选框语法错误

c# - 如何将命令行参数传递给 MSI 安装程序