0

In my .NET Framework 4.7.2 ConsoleApp with AnyCPU, i am tracing different assemblies loaded in current appdomain with AppDomain.CurrentDomain.GetAssemblies()

  public static void Main(string[] args)
    {  
        Console.WriteLine(typeof(System.Data.CommandBehavior).Assembly.Location);
        Console.WriteLine(typeof(System.Collections.ArrayList).Assembly.Location);
        Console.WriteLine(typeof(HashSet<>).Assembly.Location);
        foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
        {
            Console.WriteLine(assembly.Location);
        }
        Console.ReadKey();
    }

and here is the result:

  • mscorlib.dll loaded from Framework directory (this path C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll)
  • System.Core.dll loaded from GAC_MSIL Directory (this path C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll)
  • System.Data.dll loaded from GAC_32 Directory (this path C:\windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll)

known that the CLR loads assemblies using :

1-GAC

2-Current directory

My questions are :

  • what is the role of Framework/Framwork64 Folder in CLR loading assemblies process (i know it's where .net framework runtimes installed)
  • Does this CLR loads only runtime assemblies from this folder ? if yes is there any order ?
  • My application is targeting AnyCPU why it loads assemblies from GAC_32 instead of GAC_MSIL?
  • Something doesn't add up here. .NET Core doesn't use the GAC. Are you sure it's a .NET Core application? I was unable to reproduce it. I see assemblies loaded from `C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.13`. Please provide a [mre]. – madreflection Apr 01 '21 at 18:10
  • the GAC is an implementation detail you shouldn't really concern yourself with – Daniel A. White Apr 01 '21 at 22:12
  • @madreflection yes i made a typo, it's .NET Framework 4.7.2, for .NET Core you are right it's loaded from shared directory.i have provided the sample code to reproduce it. – youssef jirari Apr 01 '21 at 22:33
  • @DanielA.White can you please elaborate, in my case i am working on a tool that simulates runtime loading assemblies, so i should consider GAC , because it's the first place where the runtime looks for assemblies as metioned here https://learn.microsoft.com/fr-fr/dotnet/framework/deployment/how-the-runtime-locates-assemblies – youssef jirari Apr 01 '21 at 22:37
  • how are you writing your tool? what i mean is that the directory structure changed between versions and that it is an _internal_ detail for .net to manage. you can use the `gacutil` - https://learn.microsoft.com/en-us/dotnet/framework/tools/gacutil-exe-gac-tool to inspect it. – Daniel A. White Apr 02 '21 at 02:03
  • These assemblies have caused a [fair amount of trouble](https://stackoverflow.com/a/13750130/17034). Only remaining use is to act as the reference assemblies for System.CodeDom-generated code. Plus whatever custom scripting facility has been built into existing programs. – Hans Passant Apr 05 '21 at 14:16

0 Answers0