我如何确定是否正在使用本机图像,而加载程序没有在运行时验证程序集的签名,甚至使用 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