NGEN 程序集未加载
我正在尝试衡量对我的程序集进行 NGEN 处理与不进行 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
Why isn't it Binding it Correctly? FWIW,该应用程序大量使用 MEF;我不知道这是否会影响程序集的加载。
I'm trying to measure the performance impact of NGENing my assemblies versus not but I am unable to get my executable to load the NGEN assemblies. I ran the following from the VS2010 command prompt:
ngen install MyApp.exe
This completed without any issues and I verified that all my dependency assemblies had been created in the C:\Windows\assembly\NativeImages_v4.0.30319_32\MyCompanyName# directory.
I then launched my app and looking at Process Explorer, it was loading all my assemblies from the local binaries directory instead of loading the *.ni.dll files from the NativeImages_x folder. I logged the bindings using fuslogvw. Here is a sample log entry:
*** 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
Does anyone have any thoughts on what is going on here? I verified that the native assembly in question exists at:
C:\Windows\assembly\NativeImages_v4.0.30319_32\MyCompanyName#\3a041121abf7fbdce89836c32f2d217e\MyCompanyName.MyAssembly.ni.dll
Why isn't it binding it correctly? FWIW, the application uses MEF quite a bit; I don't know if that would affect the loading of the assemblies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为使用了MEF。 NGEN 只能遵循程序集引用。但如果您使用 MEF,那么您可能不会引用所有程序集,因为 MEF 负责在运行时动态加载它们。
你的方法是正确的。使用 NGEN 调用所有程序集。
在这种情况下,您需要在卸载应用程序时手动从缓存中删除这些程序集。
另请参阅:http://msdn.microsoft.com /en-us/library/6t9t5wcf(v=vs.100).aspx
It's because of using MEF. NGEN is only able to follow assembly references. But if you use MEF then you probably don't refer all the assemblies because MEF is responsible to load them dynamically at runtime.
Your approach is the right one. Call all assemblies with NGEN.
In this case you need to remove these assemblies manually from the cache when the application is uninstalled.
See also: http://msdn.microsoft.com/en-us/library/6t9t5wcf(v=vs.100).aspx
我不知道实际问题是什么,但解决方案是编写一个批处理文件,简单地对目录中的每个二进制文件进行 NGEN 处理。我猜想当在顶级 exe 上运行 ngen install 命令时,有些二进制文件没有被 NGEN 处理。
I don't know what the actual issue was but the solution was to write a batch file that simply NGEN'd every binary in the directory. I guess there were binaries that were not being NGEN'd when running just the ngen install command on the top-level exe.