C# DllNotFoundException,但存在 DLL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1246486/
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
DllNotFoundException, but DLL is there
提问by Asmor
So I'm using an SDK for a hardware random number generator which provides a dll called PsyREG.dll for interacting with it, as well as some c# source for using the methods from the dll.
因此,我将 SDK 用于硬件随机数生成器,它提供了一个名为 PsyREG.dll 的 dll 用于与其交互,以及一些用于使用来自 dll 的方法的 c# 源代码。
It has worked in the past, but somehow it has stopped working. My hands are a bit tied as I don't actually have access to the device in question at the moment, so I can't try a lot of things...
它过去一直有效,但不知何故它已停止工作。我的手有点绑,因为我目前实际上无法访问有问题的设备,所以我无法尝试很多东西......
However, here's the weird thing. The dll is there, the same place it's always been. Ahd in fact File.Exists("PsyREG.dll") returns true, and I've double checked and that's the exact same way the provided c# source imports it, e.g. [DllImport("PsyREG.dll")].
然而,奇怪的事情来了。dll 就在那里,它一直在同一个地方。Ahd 实际上 File.Exists("PsyREG.dll") 返回 true,我已经仔细检查过,这与提供的 c# 源导入它的方式完全相同,例如 [DllImport("PsyREG.dll")]。
Any ideas?
有任何想法吗?
采纳答案by Cleiton
It is probably this dll has some dependencies that they arent registred or arent in the same folder of your application.
可能是这个 dll 有一些依赖项,它们没有注册或不在您的应用程序的同一文件夹中。
回答by Joseph
Perhaps you should check to see if you're expecting a specific product version of the dll, and make sure that the product versions still match up correctly.
也许您应该检查一下您是否需要特定产品版本的 dll,并确保产品版本仍然正确匹配。
回答by cbuteau
Open DLL on the problematic system in http://www.dependencywalker.com/
在有问题的系统上打开 DLL http://www.dependencywalker.com/
回答by Maghoumi
I was dealing with the same exception with regards to one of my DLL's (let's call it A
). C# was crashing because it claimed it couldn't find this DLL (A
) (while it was there in the same folder as the executable).
我正在处理与我的 DLL 之一有关的相同异常(我们称之为A
)。C# 崩溃是因为它声称找不到这个 DLL ( A
)(虽然它与可执行文件位于同一文件夹中)。
Turned out that the issue was caused by A
having dependency on another DLL (call it B
). B
was not in the path so A
couldn't load it when it needed it. Since B
needed a whole bunch of other DLL's, the solution was to add B
's directory to the PATH
environment variable.
原来这个问题是由于A
对另一个 DLL 的依赖引起的(称之为B
)。B
不在路径中,因此A
无法在需要时加载它。由于B
需要一大堆其他 DLL,解决方案是将B
's 目录添加到PATH
环境变量中。
It's interesting how C# crashes with the error saying that A
is not found when in fact B
was not found...
有趣的是,C# 是如何因错误而崩溃的,但A
实际上未找到时却说B
未找到...
回答by kjhf
I ran into this problem and solved with the following:
我遇到了这个问题并解决了以下问题:
There's a dependency on msvcr90.dll if you compile under /MD. Try compiling the code with /MT instead.
如果在 /MD 下编译,则对 msvcr90.dll 有依赖性。尝试使用 /MT 编译代码。
Project properties
> C/C++
> Code Generation
> Runtime Library: /MT
Project properties
> C/C++
> Code Generation
>Runtime Library: /MT