I think I am not very clear about those different loading functions, so I looked up a couple of different sources, and it helps a lot. Here are some understanding I summarized:
- If possible, it's better to call Load instead of LoadFrom since the later has to call the first anyway.
- LoadFrom actually calls the Load method: Internally, LoadFrom will firstly try to get the AssemblyName by call System.Reflection.AssemblyName.GetAssemblyName( path) method, then it will call Assembly's Load method, passing it the AssemblyName object. If load fails to find an assembly, then LoadFrom loads the assembly at the path name specified in the LoadFrom method. It is possible that there exist two different assemblies which have the same identity, so when LoadFrom internally calls Load, it may load an assembly which is different with the path you specified in the LoadFrom.
- LoadFile will load the assembly without CLR applying any policies or searching.
- When Load looks for the assembly, it will be based on the following searching path:
- Application's base directory.
- Private path subdirectories.
- code base locations.
- Load has two versions, one is Load(AssembyName), the other is Load(String). When you use the the second method to load, your normally pass in a string like this "mscorlib, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b77a5c561934e089". Remember, the first section of the string is name, which doesn't include the path and extension. If you choose to use AssemblyName to load, there are three situations.
- You didn't specify the codebase, but include other bits. If you don't specify the code base, and set the AssemblyName.Name, CultureInfo, public key token / public key and/or Version properties, it's essentially the same as the Load(String), because you just parse out that string and put it in individual fields.
- You specify the codebase, not the name. The code base will have the format look like "file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll", and if you set the codebase, not the name, then, it's doing the same thing as Assembly.LoadFrom() method based on that code base.
- When both are specified, then we do step 1 firstly, and if step 1 failed, we do step 2. The thing which worth noting is when you call Assembly.Load(AssemblyName) with a codepath, it does not mean the assembly will be loaded from that path.