How to identify if a GAC assembly is loading

2020-04-21 02:35发布

问题:

I have installed Visual Studio 2011 beta, and have found that a website I was working on has since stopped working. It has been suggested that there is an MVC or Razor assembly from the GAC which is loading and taking over. How would I check this?

回答1:

Run the application in Debug mode and watch the Output window in Visual Studio. It will list every assembly as it is loaded, you will recognize GAC assemblies easily by its full file path.



回答2:

Just of interest let's do it i runtime. The idea is - check out Assembly.GlobalAssemblyCache property of all loaded MVC assemblies.

Put the following code snippet somewhere in Page_Load() and see in a file whether specific assembly was loaded from GAC:

using System.Linq;
var items = AppDomain.CurrentDomain
                     .GetAssemblies()
                     .Where(a => a.FullName.Contains("MVC"))
                     .Select(a => String.Format(
                                         CultureInfo.InvariantCulture,
                                         "[{0}] {1}",
                                         a.GlobalAssemblyCache,
                                         a.FullName));

File.WriteAllLines("c:\\assembliesdump.txt", items .ToArray());   

Output will be like shown below (log4net filter as example):

[False] log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821