2011-06-29 49 views
4

我试图衡量NGENing我的组件与未对性能的影响,但我不能让我的可执行文件来加载NGEN组件。我跑从VS2010命令提示符下:NGEN'd组件没有被加载

ngen install MyApp.exe 

这样就完成了,没有任何问题,我核实,我的所有依赖组件已在C中创建:\ WINDOWS \装配\ 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相当多;我不知道这是否会影响程序集的加载。

回答

1

我不知道什么实际的问题是,但解决办法是写一个简单NGEN'd目录中每个二进制的批处理文件。我想有只运行在NGEN的顶级EXE安装命令时没有被NGEN'd二进制文件。

+0

从你的输出上面,它看起来像你也混了64/32的二进制文件,该Framework64请求你们在_32目录检查。 –

+0

这意味着使用ngen-32位而不是ngen-64位。 – SergeyT

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