12

我如何确定是否正在使用本机图像,而加载程序没有在运行时验证程序集的签名,甚至使用 GAC 的程序集?

我有一个复杂的系统,我们正在用 NGen 进行试验,但目前我们正在从所有 DLL 所在的文件夹中运行 exe,因为有很多后期绑定依赖项,查看 Process Explorer,看起来本机图像正在使用过,但我怎样才能确定我得到了全部好处并消除了加载程序验证步骤?

干杯,格雷姆。

更新: 我从程序集绑定日志查看器中得到了很多这样的东西:

LOG: [Level 1]Start validating IL dependency MyCompany.Entities, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7cd8595f4671c5dd.
LOG: Dependency evaluation succeeded.

最后

LOG: Validation of dependencies succeeded.
LOG: Start loading all the dependencies into load context.
LOG: Loading of dependencies succeeded.
LOG: Bind to native image succeeded.
Native image has correct version information.
Attempting to use native image C:\Windows\assembly\NativeImages_v2.0.50727_32\MyCompany.Mylibrary#\4710bb8309419d707681bd360088181f\MyCompany.MyLibrary.MyClass.ni.dll.
ZAP: Native image has been relocated.
Native image successfully used.

所以它使用的是本机图像,但仍在验证它们,即不使用 GAC 版本,即使那是我创建本机图像的地方,就像这样:

ngen install "MyCompany.Entites, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7cd8595f4671c5dd, processorArchitecture=MSIL"

脚注: 这篇文章似乎暗示如果程序集不是从 GAC 加载的,那么验证过程会抵消 NGen 的优势吗? CLR 由内而外 - 提高应用程序启动性能 (MSDN)

更新- 正如 Nobugz 在下面的评论中指出的那样,自 3.5 SP1 以来未执行上述验证步骤,请参阅:MSDN Docs on NGen

4

3 回答 3

12

您可以从 Fuslogvw.exe 工具中轻松查看。从 Visual Studio 命令提示符启动它。使用 Log Categories = Native Images, Settings + Log all 绑定到磁盘进行配置。运行你的程序。回到 fuslogvw,刷新。它将向您显示已加载的所有程序集的列表。

双击一个条目以查看程序集是如何加载的。如果它来自 GAC,您将看到:

LOG:从 C:\Windows\assembly\GAC_MSIL\blahblah 加载的 IL 程序集

如果使用了 Ngen-ed 图像,您将看到:

LOG:绑定到本机映像成功。

于 2010-02-17T17:38:19.493 回答
3

You can see if the assembly came from the GAC pretty easily:

Assembly assembly = Assembly.GetExecutingAssembly();

if (assembly.GlobalAssemblyCache)
{
    Console.WriteLine("I'm in the GAC!");
}

EDIT: found a way...

In order to see if it is NGEN'd, you have to read the assembly directly and see if the Precompile Header field has data as per this page. I'm a bit rusty on getting to that value, but that should do it. I don't see a way to figure it out via the reflection methods.

于 2010-02-17T16:35:25.863 回答
1

您可以使用VMMAP。在那里,所有 .dll(程序集)都有位置详细信息

如果您的程序集是从“C:\Windows\assembly\NativeImages(version)...”加载的详细信息,那么您的应用程序正在使用本机映像。

于 2016-10-17T13:16:25.790 回答