为什么 .NET 找不到 OpenSSL.NET dll?

发布于 2024-08-04 09:11:35 字数 1487 浏览 8 评论 0 原文

编辑(整个问题,太不清楚了)

我想使用 OpenSSL.NET< /a>

OpenSSL.NET 安装说明页面:安装

确保当前工作中有libeay32.dll和ssleay32.dll 您的应用程序目录或 PATH 中。 完成
在 .NET 项目中,添加对 ManagedOpenSsl.dll 程序集的引用。 完成

我已将libeay32.dllssleay32.dll放入我的< strong>bin/Debugbin/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?

EDIT (the whole question, it was too unclear)

I want to use OpenSSL.NET

The OpenSSL.NET install instructions page: INSTALL

Make sure you have libeay32.dll and ssleay32.dll in the current working
directory of your application or in your PATH. DONE
In your .NET project, add a reference to the ManagedOpenSsl.dll assembly. DONE

I have put libeay32.dll and ssleay32.dll in both my bin/Debug and bin/Release directories. I have also put them in system32.

Here is my FULL code:

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();
        }
    }
}

I get the following error:
Unable to load DLL 'libeay32' http://localhostr.com/files/a719c5/Error.gif
(Unable to load DLL 'libeay32')

Here is the Process Monitor log (upon request):
alt text http://localhostr.com/files/726a46/ProcMon.gif

What am I doing wrong? Why isn't the DLL found?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

冬天的雪花 2024-08-11 09:11:36

执行此操作的 .NET 方法是将程序集安装在 全局程序集缓存< /a>.

每台计算机的共同之处
安装的语言运行时有一个
机器范围的代码缓存称为
全局程序集缓存。全球
程序集缓存存储程序集
特别指定共享
通过多个应用程序
计算机。

The .NET way of doing this is to install your assembly in the global assembly cache.

Each computer where the common
language runtime is installed has a
machine-wide code cache called the
global assembly cache. The global
assembly cache stores assemblies
specifically designated to be shared
by several applications on the
computer.

つ可否回来 2024-08-11 09:11:36

作为最后的手段,如果其他办法都不起作用:

了解应用程序(.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.

单身情人 2024-08-11 09:11:36

您可能缺少 VC++ 可再发行组件。我假设 OpenSSL.NET 仅支持 x86,因此您可以 获取 VS2008 版本 x86 可再发行(如果它们是发布版本)。

否则,如果它们是调试版本(您将在 EventViewer 或 sxstrace 日志中看到 Microsoft.VC90.DebugCRT),那么您需要执行以下任一操作:

  • 将它们重新编译为版本
  • 从另一台计算机安装或复制调试可再
  • 发行组件将 Visual C++ 安装到Visual Studio(或者可能是 Visual C++ Express)

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:

  • Rebuild them as release
  • Install or copy the debug redistributables from another machine
  • Install Visual C++ into Visual Studio (or, probably, Visual C++ Express)
回忆躺在深渊里 2024-08-11 09:11:36

我找到了解决方案。

不幸的是,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 :)

眼角的笑意。 2024-08-11 09:11:36

尝试将项目的平台目标更改为 x86 而不是“任何 cpu”。

Try changing the Platform target for your project to x86 instead of "any cpu".

如此安好 2024-08-11 09:11:36

就我而言,当我们在 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

enter image description here

凉月流沐 2024-08-11 09:11:36

在应用程序路径中创建名为 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.

何处潇湘 2024-08-11 09:11:35

尝试最新版本的 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.

我们的影子 2024-08-11 09:11:35

在不准确查看您的代码的情况下,当我执行以下操作时,我会收到该错误:

  • 可执行文件的路径中没有 dll(不是您的 sln 所在的位置,而是 .exe 的制作位置,通常在 bin/debug 或 bin/x86/ 中)调试或其他)。
  • 没有调用函数的正确签名(即,我遗漏了整数参数,返回类型不匹配等)。
  • 我没有正确地编组类型(即,BOOL 被编组为 bool,而 bool 被编组为无符号单字节整数,等等)——虽然最后一个可能不会导致异常,但它可能会导致明显的时髦行为。
  • 我在 64 位平台上调用 32 位 dll。指针大小将完全不同,并且 dll 可能会崩溃并导致该异常。

编辑:当所有其他方法都失败时,请尝试 dependency walker,因为听起来你的 dll 正在调用其他 dll不在您的路径或可执行文件的目录中。

Without looking at your code exactly, I get that error when I:

  • do not have the dlls in the path of the executable (not where your sln resides, but where the .exe is made, typically in bin/debug or bin/x86/debug or whatever).
  • do not have the proper signature of the calling function (ie, I left out an integer parameter, the return types don't match, etc).
  • am not marshalling the types properly (ie, BOOL is marshalled as a bool, while bool is marshalled as a unsigned single byte integer, etc)-- while this last one may not cause the exception, it can cause decidedly funky behavior.
  • am on a 64 bit platform and am calling a 32 bit dll. The pointer sizes will be all different, and the dll will probably just crash and cause that exception.

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.

我不吻晚风 2024-08-11 09:11:35

对于仍然遇到此问题的其他人(并已验证必要的先决条件是否存在于正确的位置:

检查 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.

别在捏我脸啦 2024-08-11 09:11:35

您的问题与此问题相关:

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.

哭泣的笑容 2024-08-11 09:11:35

尝试使用探测。您需要创建一个 XML 配置文件,命名为应用程序的可执行文件完整名称(或命名为需要非托管 dll 的程序集),扩展名为 .config。例如,如果您的应用程序名称为 myapp.exe,则配置文件将命名为 myapp.exe.config
配置文件必须位于与可执行文件/程序集相同的目录中。

配置文件是一个简单的 xml 文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyuBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="PATH" />
    </assemblyuBinding>
  </runtime>
</configuration>

现在应用程序将在加载程序集时在 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:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyuBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="PATH" />
    </assemblyuBinding>
  </runtime>
</configuration>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文