我正在尝试衡量 NGEN 对我的程序集的性能影响,但我无法让我的可执行文件加载 NGEN 程序集。我从 VS2010 命令提示符运行以下命令:
ngen install MyApp.exe
这完成没有任何问题,并且我验证了我的所有依赖程序集都已在 C:\Windows\assembly\NativeImages_v4.0.30319_32\MyCompanyName# 目录中创建。
然后我启动我的应用程序并查看 Process Explorer,它正在从本地二进制目录加载我的所有程序集,而不是从 NativeImages_x 文件夹加载 *.ni.dll 文件。我使用 fuslogvw 记录了绑定。这是一个示例日志条目:
*** Assembly Binder Log Entry (6/29/2011 @ 10:14:04 AM) ***
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:\Path\To\My\Binaries\MyCompanyName.MyApp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = username
LOG: DisplayName = MyCompanyName.MyAssembly, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Path/To/My/Binaries/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyCompanyName.MyApp.exe
Calling assembly : MyCompanyName.AnotherAssembly, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null.
===
LOG: Start binding of native image MyCompanyName.MyAssembly, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null.
WRN: No matching native image found.
LOG: IL assembly loaded from C:\Path\To\My\Binaries\MyCompanyName.MyAssembly.dll
有人对这里发生的事情有任何想法吗?我验证了有问题的本机程序集存在于:
C:\Windows\assembly\NativeImages_v4.0.30319_32\MyCompanyName#\3a041121abf7fbdce89836c32f2d217e\MyCompanyName.MyAssembly.ni.dll
为什么它没有正确绑定它?FWIW,该应用程序使用了相当多的 MEF;我不知道这是否会影响程序集的加载。