Determine if GAC'ed & NGen'ed assemblies are being used

后端 未结 3 1420
执念已碎
执念已碎 2020-12-14 21:42

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 ha

3条回答
  •  囚心锁ツ
    2020-12-14 22:27

    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.

提交回复
热议问题