我已经使用NGEN来创建我的应用程序使用的多个程序集的 native 镜像。但是,这些图像在运行应用程序时不会加载,我也不知道为什么。

这是来自fuslogvw的典型日志:

*** Assembly Binder Log Entry  (2/05/2012 @ 13:29:04) ***

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

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\MyDir\MyApp.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = ***\***
LOG: DisplayName = MyAssembly, Version=1000.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified)
LOG: Appbase = file:///C:/MyDir/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyApp.exe
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: Start binding of native image MyAssembly, Version=1000.0.0.0, Culture=neutral, PublicKeyToken=null.
WRN: No matching native image found.
LOG: IL assembly loaded from C:\MyDir\MyAssembly.dll.

还有来自ngen.exe的有关该程序集的信息:
C:\MyDir>ngen display MyAssembly.dll
Microsoft (R) CLR Native Image Generator - Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

NGEN Roots:

C:\MyDir\MyAssembly.dll

NGEN Roots that depend on "C:\MyDir\MyAssembly.dll":

C:\MyDir\MyAssembly.dll

Native Images:

MyAssembly, Version=1000.0.0.0, Culture=neutral, PublicKeyToken=null

我使用了位于C:\Windows\Microsoft.NET\Framework\v4.0.30319\中的ngen.exe,程序集的目标框架是.NET Framework4。创建 native 镜像后,我没有重新编译程序集。

任何帮助,将不胜感激。

最佳答案



您的进程以64位模式运行,这是默认的64位操作系统上的AnyCPU目标。这要求您运行ngen.exe的64位版本。确保选择正确的Visual Studio命令提示符。有两种方法,一种为64位工具设置环境的方法,在“开始”菜单中名为“Visual Studio x64 Win64命令提示符(2010)”。

关于未加载使用NGEN创建的.NET native 镜像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10413987/

10-09 12:29