.net 无法加载文件或程序集“***.dll”或其依赖项之一
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4411020/
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
Could not load file or assembly '***.dll' or one of its dependencies
提问by Dewm Solo
I have this dll that I created a long time ago and use to connect to the db of a specific software that I develop for. I have had no issues for well over 4 years and countless applications with this dll.
我有一个很久以前创建的 dll,用于连接到我开发的特定软件的数据库。4 年多来,我一直没有遇到任何问题,并且使用此 dll 的应用程序数不胜数。
Trying to deploy my latest creation, I get the following error:
尝试部署我的最新作品时,出现以下错误:
System.IO.FileNotFoundException: Could not load file or assembly '***.dll' or one of its dependencies. The specified module could not be found.
So, for every dll I ever wrote, I always made a simple forms application to test that dll just by itself. Running that simple app yielded the same error. The dll doesn't load or use anything else than: System, System.Data, System.XML. So as far as depencies of it go, I don't see anything wrong.
因此,对于我写过的每个 dll,我总是制作一个简单的表单应用程序来单独测试该 dll。运行那个简单的应用程序产生了同样的错误。dll 不加载或使用除以下内容之外的任何内容:System、System.Data、System.XML。所以就它的依赖而言,我没有看到任何错误。
By the way everything works on a dev station. The problem is limited to deployment stations. .Net and the necessary redistributables, since I do everything in C++, are deployed and working.
顺便说一下,一切都在开发站上运行。问题仅限于部署站。.Net 和必要的可再发行组件,因为我在 C++ 中做所有事情,已经部署和工作。
Running FUSLOGVW.exe showed everything as working fine.
运行 FUSLOGVW.exe 显示一切正常。
Running depends.exe said: Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
运行depends.exe 说:警告:由于延迟加载相关模块中缺少导出功能,至少有一个模块具有未解析的导入。
I already tried rewriting the whole thing. Which yielded the same results.
我已经尝试重写整个事情。这产生了相同的结果。
Clues anyone?
有线索吗?
EDITS
编辑
Here is the total error message:
这是总错误消息:
See the end of this message for details on invoking \"
just-in-time (JIT) debugging instead of this dialog box.\"
************** Exception Text **************\"
System.IO.FileNotFoundException: Could not load file or assembly 'connectionTo.dll' or one of its dependencies. The specified module could not be found.\"
File name: 'connectionToJobboss32.dll'\"
at TESTConnection.Form1.button1_Click(Object sender, EventArgs e)\"
at System.Windows.Forms.Control.OnClick(EventArgs e)\"
at System.Windows.Forms.Button.OnClick(EventArgs e)\"
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)\"
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\"
at System.Windows.Forms.Control.WndProc(Message& m)\"
at System.Windows.Forms.ButtonBase.WndProc(Message& m)\"
at System.Windows.Forms.Button.WndProc(Message& m)\"
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\"
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\"
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\"
\"
************** Loaded Assemblies **************\"
mscorlib\"
Assembly Version: 4.0.0.0\"
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)\"
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll\"
----------------------------------------\"
TESTConnection\"
Assembly Version: 1.0.3996.18980\"
Win32 Version: \"
CodeBase: file:///C:/Program%20Files%20(x86)/conn/TESTConnection.exe\"
----------------------------------------\"
System.Windows.Forms\"
Assembly Version: 4.0.0.0\"
Win32 Version: 4.0.30319.1 built by: RTMRel\"
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll\"
----------------------------------------\"
System.Drawing\"
Assembly Version: 4.0.0.0\"
Win32 Version: 4.0.30319.1 built by: RTMRel\"
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll\"
----------------------------------------\"
System\"
Assembly Version: 4.0.0.0\"
Win32 Version: 4.0.30319.1 built by: RTMRel\"
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll\"
----------------------------------------\"
There is no errors in the event viewer.
事件查看器中没有错误。
回答by Hans Passant
or one of its dependencies
或其依赖项之一
That's the usual problem, you cannot see a missing unmanaged DLL with Fuslogvw.exe. Best thing to do is to run SysInternals' ProcMon utility. You'll see it searching for the DLL and not find it. Profile mode in Dependency Walker can show it too.
这是常见的问题,您无法通过 Fuslogvw.exe 看到丢失的非托管 DLL。最好的办法是运行 SysInternals 的 ProcMon 实用程序。您会看到它在搜索 DLL 而没有找到它。Dependency Walker 中的配置文件模式也可以显示它。
回答by light
I had the same issue with a dll yesterday and all it referenced was System, System.Data, and System.Xml. Turns out the build configuration for the Platform type didn't line up. The dll was build for x86 and the program using it was "Any CPU" and since I am running a x64 machine, it ran the program as x64 and had issues with the x86 dll. I don't know if this is your issue or not, just thought that I would mention it as something else to check.
昨天我在一个 dll 上遇到了同样的问题,它引用的只是 System、System.Data 和 System.Xml。原来平台类型的构建配置没有对齐。dll 是为 x86 构建的,使用它的程序是“任何 CPU”,因为我运行的是 x64 机器,它以 x64 运行程序,并且 x86 dll 有问题。我不知道这是否是你的问题,只是想我会提到它作为其他检查。
回答by danw
I recently hit this issue, the app would run fine on the developer machines and select others machines but not on recently installed machines. It turned out that the machines it did work on had the Visual C++ 11 Runtime installed while the freshly installed machines didn't. Adding the Visual C++ 11 Runtime redistributable to the app installer fixed the issue...
我最近遇到了这个问题,该应用程序可以在开发人员机器上正常运行并选择其他机器,但不能在最近安装的机器上运行。事实证明,它运行的机器安装了 Visual C++ 11 运行时,而新安装的机器没有。将 Visual C++ 11 运行时可再发行组件添加到应用安装程序修复了该问题...
回答by Henric Rosvall
I had the same problem. For me, it was caused by the default settings in the local IIS server on my machine. So the easy way to fix it, was to use the built in Visual Studio development server instead :)
我有同样的问题。对我来说,这是由我机器上本地 IIS 服务器中的默认设置引起的。所以修复它的简单方法是使用内置的 Visual Studio 开发服务器:)
Newer IIS versions on x64 machines have a setting that doesn't allow 32 bit applications to run by default. To enable 32 bit applications in the local IIS, select the relevant application pool in IIS manager, click "Advanced settings", and change "Enable 32-Bit Applications" from False to True
x64 计算机上较新的 IIS 版本具有不允许 32 位应用程序默认运行的设置。要在本地IIS中启用32位应用程序,在IIS管理器中选择相关的应用程序池,点击“高级设置”,将“启用32位应用程序”从False改为True
回答by Jim Mischel
I ran into this recently. It turned out that the old DLL was compiled with a previous version (Visual Studio 2008) and was referencing that version of the dynamic runtime libraries. I was trying to run it on a system that only had .NET 4.0 on it and I'd never installed any dynamic runtime libraries. The solution? I recompiled the DLL to link the static runtime libraries.
我最近遇到了这个。原来,旧的 DLL 是用以前的版本 (Visual Studio 2008) 编译的,并且引用了该版本的动态运行时库。我试图在只有 .NET 4.0 的系统上运行它,而且我从未安装过任何动态运行时库。解决方案?我重新编译了 DLL 以链接静态运行时库。
Check your application error log in Event Viewer (EVENTVWR.EXE). It will give you more information on the error and will probably point you at the real cause of the problem.
在事件查看器 (EVENTVWR.EXE) 中检查您的应用程序错误日志。它将为您提供有关错误的更多信息,并可能会指出问题的真正原因。
回答by RenniePet
This answer is totally unrelated to the OP's situation, and is a very unlikely scenario for anyone else too, but just in case it may help someone ...
这个答案与 OP 的情况完全无关,对于其他任何人来说也是一种不太可能的情况,但以防万一它可能对某人有所帮助......
In my case I was getting "Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0 ..." because I had disassembled and reassembled the program using ILDAsm.exe and ILAsm.exe from .Net Framework / SDK version 2. Switching to ILDAsm.exe and ILAsm.exe from .Net Framework / SDK version 4 fixed the problem.
在我的情况下,我收到“无法加载文件或程序集'System.Windows.Forms,版本 = 4.0.0.0 ...”,因为我已经使用 .Net Framework 中的 ILDAsm.exe 和 ILAsm.exe 反汇编并重新组装了程序/ SDK 版本 2。从 .Net Framework/SDK 版本 4 切换到 ILDAsm.exe 和 ILAsm.exe 解决了该问题。
(Strangely, even though doing what I did may seem like an obvious error, the resulting EXE file that didn't work did indicate that it targeted .Net 4 when examined with JetBrains dotPeek.)
(奇怪的是,尽管我所做的看起来似乎是一个明显的错误,但在使用 JetBrains dotPeek 检查时,生成的无效 EXE 文件确实表明它针对 .Net 4。)
回答by outofmind
I had the same issue - a .dll working all the time, then my computer crashed and afterwards I had this problem of 'could not load file or assembly ....dll'
我遇到了同样的问题 - 一个 .dll 一直在工作,然后我的电脑崩溃了,之后我遇到了“无法加载文件或程序集 ....dll”的问题
Two possible solutions: when the computer crashed there may be some inconsistent files in
两种可能的解决方法:当电脑死机时可能有一些不一致的文件
C:\Users\<yourUserName>\AppData\Local\Temp\Temporary ASP.NET Files
Deleting that folder, recompiling and the error was gone.
删除该文件夹,重新编译,错误消失了。
Once I had also to delete my packages folder (I had read that somewhere else). Allow Visual Studio / nuget to install missing packages (or manually reinstall) and afterwards everything was fine again.
有一次我还必须删除我的包文件夹(我在其他地方读过)。允许 Visual Studio / nuget 安装丢失的包(或手动重新安装),然后一切又正常了。
回答by Ghukas
Had the same issue and got it resolved by making sure projects in the solution have the same configuration and platform (in my case it was Debug x64). Somehow the VIsual Studio was missing x64 for part of the projects and I edited the .sln file manually (copied the configurations and platforms from correctly built projects to the projects that were missing the settings I needed). This is what it looks like for one of the projects:
遇到了同样的问题,并通过确保解决方案中的项目具有相同的配置和平台来解决它(在我的情况下它是 Debug x64)。不知何故,VIsual Studio 的部分项目缺少 x64,我手动编辑了 .sln 文件(将配置和平台从正确构建的项目复制到缺少我需要的设置的项目)。这是其中一个项目的样子:
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Debug|x64.ActiveCfg = Debug|x64
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Debug|x64.Build.0 = Debug|x64
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Release|Any CPU.Build.0 = Release|Any CPU
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Release|x64.ActiveCfg = Release|x64
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Release|x64.Build.0 = Release|x64
But then the same error occurred for a project that had a Java file (*.jar) in the dependencies. I had to edit Environment Variables manually to create a record with this value
但是,对于在依赖项中有 Java 文件 (*.jar) 的项目,发生了同样的错误。我必须手动编辑环境变量才能使用此值创建记录
C:\Program Files\Java\jre1.8.0_171\bin\server
C:\Program Files\Java\jre1.8.0_171\bin\server
for Java's path, and put it on top of the Path items.
对于 Java 的路径,并将其放在 Path 项的顶部。
This fixed the issue until I updated Java on my machine. I had to edit the version number in Environment Variables to match the updated folder name.
这解决了这个问题,直到我在我的机器上更新了 Java。我必须编辑环境变量中的版本号以匹配更新的文件夹名称。
C:\Program Files\Java\jre1.8.0_181\bin\server
C:\Program Files\Java\jre1.8.0_181\bin\server
回答by user3490852
1) Copy DLLs from "Externals\ffmpeg\bin" to your project's output directory (where executable stays); 2) Make sure your project is built for x86 target (runs in 32-bit mode).
1) 将 DLL 从“Externals\ffmpeg\bin”复制到项目的输出目录(可执行文件所在的位置);2) 确保您的项目是为 x86 目标构建的(以 32 位模式运行)。
回答by Steve Rukuts
An easier way to determine what dependencies a native DLL has is to use Dependency Walker - http://www.dependencywalker.com/
确定本机 DLL 具有哪些依赖项的更简单方法是使用 Dependency Walker - http://www.dependencywalker.com/
I analysed the native DLL and discovered that it depended on MSVCR120.DLL and MSVCP120.DLL, both of which were not installed on my staging server in the System32 directory. I installed the C++ runtime on my staging server and the issue was resolved.
我分析了本机 DLL,发现它依赖于 MSVCR120.DLL 和 MSVCP120.DLL,这两个都没有安装在我的 System32 目录中的登台服务器上。我在登台服务器上安装了 C++ 运行时,问题得到了解决。

