Freigeben über


ASP.net assembly loading from GAC or Bin

For quite a while I have been going back and forth reading msdn documentations to figure out how does an assembly gets loaded at runtime. When an assembly is in the bin of your application and also in the GAC, what gets loaded at runtime, GAC or bin? This post is a quick reference guide so that I come back to it and get the short answer rather than parse through the msdn documentation each time.

What is the answer?

The Runtime first looks in the GAC and then in the probing path of the application which includes the bin to load an assembly.

What does this imply?

  • If you have 2 assemblies with the same version, one in GAC and other in bin, the assembly in GAC is loaded
  • If you have 2 assemblies with different versions, one in GAC and other in bin, and the version to load is not specified in the config, then GAC is loaded
  • If you have 2 assemblies with different versions, one in GAC and other in bin, and the version to load is specified in the config, then the specified version of the assembly is loaded either from GAC or bin, wherever the runtime finds it first.

Reference:

How the Runtime Locates Assemblies

Tools:

Fuslogvw.exe (Assembly Binding Log Viewer)

Comments