为什么 .NET 找不到 OpenSSL.NET dll?
编辑(整个问题,太不清楚了)
我想使用 OpenSSL.NET< /a>
OpenSSL.NET 安装说明页面:安装
确保当前工作中有libeay32.dll和ssleay32.dll 您的应用程序目录或 PATH 中。 完成
在 .NET 项目中,添加对 ManagedOpenSsl.dll 程序集的引用。 完成
我已将libeay32.dll
和ssleay32.dll
放入我的< strong>bin/Debug
和 bin/Release
目录。我还将它们放入 system32
中。
这是我的完整代码:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
OpenSSL.Crypto.RSA rsa = new OpenSSL.Crypto.RSA();
}
catch (Exception e)
{
Console.WriteLine(e.InnerException.Message);
}
Console.Read();
}
}
}
我收到以下错误: 无法加载 DLL 'libeay32' http://localhostr.com/files/a719c5/Error.gif< /a> (无法加载 DLL 'libeay32')
这是进程监视器日志(根据请求): 替代文本 http://localhostr.com/files/726a46/ProcMon.gif
我做错了什么?为什么找不到 DLL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
执行此操作的 .NET 方法是将程序集安装在 全局程序集缓存< /a>.
The .NET way of doing this is to install your assembly in the global assembly cache.
作为最后的手段,如果其他办法都不起作用:
了解应用程序(.net 或非 .net)在哪里寻找 DLL 可能会很有用。只需使用 进程监视器 并筛选 DLL 的文件名即可。然后将其复制到应用程序正在查找它的位置。
As a last resort, if nothing else works:
It may be useful to know where the application (.net or not) is looking for the DLLs. Just use Process Monitor and filter for the file name of the DLL. Then copy it to a location where the application is looking for it.
您可能缺少 VC++ 可再发行组件。我假设 OpenSSL.NET 仅支持 x86,因此您可以 获取 VS2008 版本 x86 可再发行(如果它们是发布版本)。
否则,如果它们是调试版本(您将在 EventViewer 或 sxstrace 日志中看到 Microsoft.VC90.DebugCRT),那么您需要执行以下任一操作:
You're probably missing the VC++ redistributables. I'm assuming OpenSSL.NET is x86 only, so you can grab the VS2008 version x86 redistributable if they're release builds.
Otherwise, if they're debug builds (you'll see Microsoft.VC90.DebugCRT in EventViewer or the sxstrace logs) then you'll need to either:
我找到了解决方案。
不幸的是,VS2008 C++ Redistributable 软件包无法工作 - 我必须安装 SP1 版本和 VC++2008。作者在其网站上的评论中表示,这是其一方的错误,而不是我的错误。他目前正在重新编译 DLL 以进行静态链接。感谢所有帮助过我的人:)
I found a solution.
Unfortunately the VS2008 C++ Redistributable package didn't work - I had to install the SP1 version AND VC++2008. The author said in a comment on its website that it was a mistake on its side, and not mine. He is currently recompiling the DLLs to be statically linked. Thank you to all of those who helped me :)
尝试将项目的平台目标更改为 x86 而不是“任何 cpu”。
Try changing the Platform target for your project to x86 instead of "any cpu".
就我而言,当我们在 x64 win 2008 平台上开发一个开放 ssl 的网站时,我们必须检查应用程序池:允许 32 个应用程序:true
In my case, when we develop a web site with open ssl on x64 win 2008 platforms, we must check with application pool : allow 32 applications : true
在应用程序路径中创建名为 x86 的新文件夹,然后将 libeay32.dll、ssleay32.dll 放入 x86 文件夹中。
Create New Folder Named x86 in your application path and then put libeay32.dll,ssleay32.dll in x86 folder.
尝试最新版本的 OpenSSL.NET (0.4.1),它现在应该包含静态链接到 CRT 的预构建 libeay32.dll 和 ssleay32.dll 二进制文件。或者,您可以自己构建这些库或使用 openssl.org 的“官方”构建。
Try the latest version of OpenSSL.NET (0.4.1) which should now include prebuilt libeay32.dll and ssleay32.dll binaries that link to the CRT statically. Alternatively, you can build these libraries yourself or use an 'official' build from openssl.org.
在不准确查看您的代码的情况下,当我执行以下操作时,我会收到该错误:
编辑:当所有其他方法都失败时,请尝试 dependency walker,因为听起来你的 dll 正在调用其他 dll不在您的路径或可执行文件的目录中。
Without looking at your code exactly, I get that error when I:
EDIT: When all else fails, try dependency walker, because it sounds like your dlls are calling other dlls that aren't in your path or in the directory of the executable.
对于仍然遇到此问题的其他人(并已验证必要的先决条件是否存在于正确的位置:
检查 OpenSSL.NET 安装文档 并确保安装其必备组件。 就我而言,用户缺少 Microsoft Visual C++ 2010 Redistributable Package (x86) 依赖项。
For anyone else out there still experiencing this issue (and have verified that the necessary prerequisites exist in their correct locations:
Check the OpenSSL.NET installation documentation and ensure its prerequisites are installed. In my case, a user was missing the Microsoft Visual C++ 2010 Redistributable Package (x86) dependency which is called out in the OpenSSL.NET documentation.
您的问题与此问题相关:
DllNotFoundException,但 DLL 存在
验证所有依赖项是否位于应用程序的同一文件夹中或是否已注册。
Your problem is related with this question:
DllNotFoundException, but DLL is there
Verify if all depencencies are in same folder of your application or are registred.
尝试使用探测。您需要创建一个 XML 配置文件,命名为应用程序的可执行文件完整名称(或命名为需要非托管 dll 的程序集),扩展名为 .config。例如,如果您的应用程序名称为 myapp.exe,则配置文件将命名为 myapp.exe.config
配置文件必须位于与可执行文件/程序集相同的目录中。
配置文件是一个简单的 xml 文件:
现在应用程序将在加载程序集时在 PATH 中搜索。 PATH 相对于配置/程序集文件。
不确定它是否适用于非托管 dll,但值得一试。
Try using probing. You need to create an XML config file named as the application's executable complete name (or named as the assembly that requieres your non-managed dll) with a .config extension. E.g. if your applications is name myapp.exe, the config file will be named myapp.exe.config
The config file must be located in the same directory as the executable / assembly .
The config file is a simple xml file:
Now the application will search in PATH when loading the assemblies. PATH is relative to the config /assembly file.
Not sure if it will work for non-managed dlls, but is worth the try.