⬅ Bradenkoh.com

How Runtime Locates and Binds Assemblies

#Programming

Source : .NET - How the Runtime Locates Assemblies - .matrixpost.net

Binding and locating assemblies is mainly how runtime can run the actual code that you built. Because your functions that you write depend on libraries and those libraries depend on other libraries, there needs to be a way of locating the right ones at the right time.

There are 4 steps that runtime uses to locate and bind an assembly

  1. Determines the correct assembly version from the configuration files. These are mainly the application, publisher and machine configuration files to see if there is any information in there that helps locate the bind or any version limitations.
    • These are normally .xml based files
  2. Check if the assembly has been bound before. If it is, it doesn't have to search, it will just use the found binding
  3. Checks the global assembly cache
    • There might be a several libraries that depend on the same library, a global cache allows this to only happen once and prevents duplicate binding
  4. Assembly probing
    • This is pretty big and more extensive and tends to be the method for addins that require external dependencies.
      • It first uses the location hints on a configuration file
      • If a codebase is found, it uses it to check for the locations. If it fails, no other probing occurs
        • Generally refers to a <CodeBase> node in the configuration file
      • Uses in built heuristics to find the assembly but if it can't find it then it will notify the user