Conclusion: if there are two strongly-named assemblies with the same Assembly name, one is in GAC, and the other is not. How to dynamically load the Assembly not in the GAC? The answer is that only assembly. reflectiononlyloadfrom can be loaded.
For example, we copy the system. dll file to the D disk (note that mscorlib. dll is loaded by default in the application domain, instead of system. dll ). Then try the following method:
VaR Path = @ "D: \ system. dll ";
// Load (byte [])
Assembly. Load (file. readallbytes (PATH ));
// Loadfrom (string)
Assembly. loadfrom (PATH );
// LoadFile (string)
Assembly. LoadFile (PATH );
Next, enumerate the loaded assembly path:
Foreach (VAR ass in appdomain. currentdomain. getassemblies ())
Console. writeline (ass. Location );
The output will contain system. dll in. NET Framework GAC, instead of the system. dll in disk D.
C: \ windows \ microsoft. Net \ Assembly \ gac_msil \ System \ v4.0 _ 4.0.0.0 _ b77a5c561934e089 \ system. dll
Okay, this file can be used only after reflectiononlyloadfrom.
Code:
VaR Path = @ "D: \ system. dll ";
// Reflectiononlyloadfrom (string)
Assembly. reflectiononlyloadfrom (PATH );
// Use appdomain. reflectiononlygetassemblies ()
Foreach (VAR ass in appdomain. currentdomain. reflectiononlygetassemblies ())
Console. writeline (ass. Location );
Output:
D: \ system. dll