System.IO.FileNotFoundException:部署应用程序时无法加载文件或程序集“X”或其依赖项之一

问题描述 投票:0回答:6

我在部署应用程序时遇到了一个奇怪的问题,该应用程序引用了一个用托管 C++ 编写的程序集。

我创建了一个程序集 X,编译它并在一个名为 Starter 的 exe 文件中引用它。

Starter.exe 在本地机器上正常启动。但是,当我将 starter debug 文件夹的所有内容复制到虚拟机,并尝试在那里启动它时,它崩溃并出现以下异常:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or 
assembly 'X' or one of its dependencies. The specified module could not be found.

这对我来说没有任何意义,因为 X 与 Starter.exe 在同一个文件夹中。

什么可能导致这个问题?

更新

我已经检查了目标机器上 Reflector 中的依赖项,它能够找到所有这些的文件。

我还将所有项目的配置更改为 x86/win32。

更新

这里是来自Fusion Log的日志(位置:C:\FusionLog\Default\Starter.exe\X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null.HTM):

*** Assembly Binder Log Entry  (6/4/2012 @ 1:56:13 PM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Documents and Settings\Administrator\Desktop\tmp\k;k\Starter.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = MENKAUR-7683827\Administrator
LOG: DisplayName = X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Documents and Settings/Administrator/Desktop/tmp/k;k/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Starter.exe
Calling assembly : Starter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Documents and Settings\Administrator\Desktop\tmp\k;k\Starter.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Documents and Settings/Administrator/Desktop/tmp/k;k/X.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Documents and Settings\Administrator\Desktop\tmp\k;k\X.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null
LOG: Binding succeeds. Returns assembly from C:\Documents and Settings\Administrator\Desktop\tmp\k;k\X.dll.
LOG: Assembly is loaded in default load context.

唯一的错误在C:\FusionLog\NativeImage\Starter.exe\目录下:

*** Assembly Binder Log Entry  (6/4/2012 @ 1:56:13 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Documents and Settings\Administrator\Desktop\tmp\k;k\Starter.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = MENKAUR-7683827\Administrator
LOG: DisplayName = BookmarkWiz.Kernel, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Documents and Settings/Administrator/Desktop/tmp/k;k/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Starter.exe
Calling assembly : Starter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: Start binding of native image X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null.
WRN: No matching native image found.
LOG: IL assembly loaded from C:\Documents and Settings\Administrator\Desktop\tmp\k;k\X.dll.

我无法对程序集签名,因为它引用了其他几个未签名的程序集

c# .net deployment .net-assembly managed-c++
6个回答
29
投票

...无法加载文件或程序集“X”或它的一个依赖项 ...

很可能它无法加载另一个依赖项。

您可以尝试使用依赖项 walker 检查依赖项。

即:https://www.dependencywalker.com/

还要检查您的构建配置 (x86 / 64)

编辑: 当我从“不受信任”的网络共享中复制 zip 中的 dll 时,我也遇到过这个问题。该文件被 Windows 锁定并引发了 FileNotFoundException。

参见此处:检测到来自互联网并被 CASPOL“阻止”的 DLL


6
投票

我有同样的问题。对我来说,它有助于删除项目文件夹中的 .vs 目录。


5
投票

我通过重命名 DLL 解决了这个问题。 DLL 在上传到共享位置时已被手动重命名(版本号附加到文件名)。从下载的文件中删除版本号解决了这个问题。


2
投票

我在尝试安装 Windows 服务时也遇到了同样的问题,在我的例子中,我设法通过删除服务 .exe 的文件夹路径中的空格来解决问题,下面是在命令提示符下为我工作的命令

cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

按 ENTER 更改工作目录

InstallUtil.exe C:\MyService\Release\ReminderService.exe

按 ENTER


0
投票

对我来说,我从 Windows 资源管理器中启动应用程序(通过双击它)。然后马上就崩溃了

然后我打开

Event Viewer
的窗口并查看
Application
,它显示了错误的完整堆栈跟踪。堆栈跟踪显示与位图或图像的关系。后来发现是因为app icon not found


0
投票

有时甚至 Process Monitor 也不会向您显示 DLL 及其查找位置。

以这个场景为例,橙色是 Library Reference A,它是一个项目引用。

接下来是黄色,它是库引用 B,它也有一个对库引用 A 的引用。现在问题来了,看看绿色箭头如何指示 LibA 是一个项目引用,没有展开/折叠来查看它的子引用。

但是当我展开 Library B 时,我可以看到我可以展开 Library Reference A!当我这样做时,我看到它是一个旧版本,可能是一个 nuget 版本。这就是问题对于我的场景,引用必须使用相同版本的 DLL 或者只是全部使用项目引用。

© www.soinside.com 2019 - 2024. All rights reserved.