NGEN的装配没有加载

时间:2011-06-29 15:31:59

标签: visual-studio-2010 mef ngen assemblybinding

我试图衡量NGENing我的程序集对性能的影响,但我无法让我的可执行文件加载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相当多;我不知道这是否会影响装配的加载。

2 个答案:

答案 0 :(得分:4)

这是因为使用了MEF。 NGEN只能遵循装配参考。但是如果您使用MEF,那么您可能不会引用所有程序集,因为MEF负责在运行时动态加载它们。

你的方法是正确的。用NGEN调用所有程序集。

ngen install c:\myfiles\MyLib.dll /ExeConfig:c:\myapps\MyApp.exe

在这种情况下,您需要在卸载应用程序时从缓存中手动删除这些程序集。

ngen uninstall c:\myfiles\MyLib.dll /ExeConfig:c:\myapps\MyApp.exe

另请参阅:http://msdn.microsoft.com/en-us/library/6t9t5wcf(v=vs.100).aspx

答案 1 :(得分:1)

我不知道实际问题是什么,但解决方案是编写一个批处理文件,只是NGEN对目录中的每个二进制文件。我想在顶层exe上运行ngen install命令时,有些二进制文件没有被NGEN用。

相关问题