确定 GAC 是否已审核并同意正在使用 NGen ed 组件

发布于 2024-08-22 10:25:48 字数 1537 浏览 7 评论 0原文

如何确定是否使用本机映像而无需加载程序在运行时验证程序集的签名,甚至使用 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 起不再执行上述验证步骤,请参阅:NGen 上的 MSDN 文档

How do I determine if the Native images are being used without the Loader verifing the signature of the assembly at runtime, or even using the GAC'ed assembly?

I have complex system that we're experimenting with NGen but currently we're running the exe from the folder where all the DLL's are located due to a lot of late binding dependencies, looking at Process Explorer, it looks like the Native images are being used, but how can I be sure I'm getting the full benefit and eliminating the Loader Verification step?

Cheers,
Graeme.

Update:
I'm getting lots of this sort of thing from the Assembly Binding Log viewer:

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

and at the end

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.

So it's using the Native images but still verifying them, i.e. not using the GAC version even though that's where I created the Native image from, Like so:

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

Footnote:
This articles seems to imply that if the assemblies are not loaded from the GAC then the verification process will offset the NGen advantages?
CLR Inside Out - Improving Application Startup Performance (MSDN)

Update - As Nobugz has pointed out in a comment below, the verification step mentioned above is not performed since 3.5 SP1 see:MSDN Docs on NGen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

对不⑦ 2024-08-29 10:25:48

您可以通过 Fuslogvw.exe 工具轻松查看它。从 Visual Studio 命令提示符启动它。使用日志类别 = 本机图像、设置 + 记录所有绑定到磁盘进行配置。运行你的程序。返回fuslogvw,刷新。它将向您显示已加载的所有程序集的列表。

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

日志:从 C:\Windows\Assembly\GAC_MSIL\blahblah 加载的 IL 程序集

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

日志:绑定到本机映像成功。

You can easily see it from the Fuslogvw.exe tool. Start it from the Visual Studio Command Prompt. Configure it with Log Categories = Native Images, Settings + Log all binds to disk. Run your program. Back to fuslogvw, Refresh. It will show you a list of all assemblies that got loaded.

Double-click an entry to see how the assembly got loaded. If it came from the GAC, you'll see:

LOG: IL assembly loaded from C:\Windows\assembly\GAC_MSIL\blahblah

If the Ngen-ed images was used, you'll see:

LOG: Bind to native image succeeded.

沧桑㈠ 2024-08-29 10:25:48

您可以很容易地查看程序集是否来自 GAC:

Assembly assembly = Assembly.GetExecutingAssembly();

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

编辑:找到了一种方法...

为了查看它是否是 NGEN,您必须直接读取程序集并查看是否预编译标头字段包含此页面。我对达到这个值有点生疏,但这应该可以。我没有找到通过反射方法来解决这个问题的方法。

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.

野稚 2024-08-29 10:25:48

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

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

You can use the VMMAP. There, all the .dll (assembly) have location details

In details if your assembly is being loaded from "C:\Windows\assembly\NativeImages(version)..." so your application are using the native image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文