我在部署一个应用程序时遇到了一个奇怪的问题,该应用程序引用了一个用托管c ++编写的程序集。
我已经创建了一个程序集X,编译它并在一个名为Starter的exe文件中引用它。
Starter.exe在本地mashine上正常启动。但是,当我将启动器调试文件夹的所有内容复制到虚拟mashine并尝试在那里启动时,它会崩溃并出现以下异常:
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.
我无法签署程序集,因为它引用了其他几个未签名的程序集
答案 0 :(得分:16)
...无法加载文件或程序集“X”或其中一个依赖项 ...
很可能无法加载另一个依赖项。
您可以尝试使用依赖性walker检查依赖项。
I.e:http://www.dependencywalker.com/
同时检查您的构建配置(x86 / 64)
编辑: 当我从“不受信任的”网络共享中以zip方式复制dll时,我也遇到过这个问题。该文件被Windows锁定,并引发了FileNotFoundException。
见这里:Detected DLLs that are from the internet and "blocked" by CASPOL
答案 1 :(得分:3)
我通过重命名DLL解决了这个问题。 DLL在上载到其共享位置时已手动重命名(版本号已附加到文件名)。从下载的文件中删除版本号解决了问题。
答案 2 :(得分:2)
我有同样的问题。对我来说,它有助于删除项目文件夹中的.vs目录。
答案 3 :(得分:1)
当我尝试安装Windows服务时,我也遇到了同样的问题,我设法通过删除服务.exe的文件夹路径中的空格解决了该问题,以下是在命令提示符
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
按ENTER更改工作目录
InstallUtil.exe C:\MyService\Release\ReminderService.exe
按ENTER
答案 4 :(得分:0)
对我来说,我是从Windows资源管理器中启动该应用程序的(双击该应用程序)。然后它立即崩溃了。
然后我打开Event Viewer
窗口并查看Application
,它显示了错误的完整堆栈跟踪。 stacktrace显示了与位图或图像的关系。后来发现这是由于找不到应用程序图标
答案 5 :(得分:0)
的伙计们,我在每个论坛上都读到有关该主题的信息,但我仍然有问题(尝试从git进行投影)
四个小时后,我发誓我只是通过更改项目属性中的目标框架设置(右键单击项目->属性)->应用程序并将目标框架从.net core 3.0更改为.net来自己解决了此问题。 5.0我希望它将对任何人都有帮助
快乐的编码gl hf书呆子