Fusion is the name of the technology that we use to load assemblies into a process or an application domain. The basic procedure used to find assemblies is the following:
Determine the version number of the requested assembly.
Check to see if we have loaded that assembly already.
Check the Global Assembly Cache (GAC).
Search for the assembly.
In the search for the assembly, if there are no configuration or publisher policies in effect, and the bind request was generated using Assembly.LoadFrom, we use the path given to the LoadFrom method. If a codebase attribute is found in the configuration file, we check its path. If we do not find the assembly, we need to probe for the assembly. We check the application base—the location where the executable (EXE) was loaded from, using the culture and name of the assembly. We search the privatePath followed by the AppendPrivatePath values.
It is important to remember that we check the GAC only for assemblies that are strong-named. The GAC is used to store assemblies that are used by more than one application. Strong-named assemblies are those that have been signed using the sn.exe tool. If your assemblies are not strong-named, you have the luxury of not needing to worry about this; just make sure that you place your assemblies in the same directory as the EXE.
As you probably have guessed, the most common error in loading assemblies is the dreaded FileNotFoundException. To troubleshoot this, you should use the fusion logs, which you can view in Visual Studio or by using fuslogvw.exe. If you use fuslogvw.exe, select its Settings option and enable Log Bind Failures to Disk. Then run the process and get the error. Finally, select the Refresh option in fuslogvw.exe, and you should be able to see the appropriate log. Fuslogvw.exe modifies the Registry path HKLM\Software\Microsoft\Fusion.
There are several methods that are provided to enhance the loading of managed assemblies, such as the following:
The Assembly.LoadFrom method allows you to load an assembly given a filename and path.
The Assembly.Load method loads an assembly and searches the GAC, application base, and private bin paths.