代码:
1 using System; 2 using System.Reflection; 3 namespace Assembly_Load 4 { 5 class Program 6 { 7 public static void Get_GAC_assembly() 8 { 9 string longName = "Roslynator.Core, Version=2.1.0.1, Culture=neutral, PublicKeyToken=926ea54d246a765e"; 10 Assembly assem = Assembly.Load(longName); 11 if (assem == null) 12 Console.WriteLine("Unable to load assembly..."); 13 else 14 Console.WriteLine(assem.FullName); 15 } 16 public static void Get_absolute_path() 17 { 18 byte[] buffer = System.IO.File.ReadAllBytes(@"D:VS2017WorkSpaceBUGExceptionSystem.MissingMethodExceptionAssembly-LoadAssembly-LoaddataRoslynator.Core.dll"); 19 //Load assembly using byte array 20 Assembly assembly = Assembly.Load(buffer); 21 Console.WriteLine(assembly.FullName); 22 Console.WriteLine("***"); 23 } 24 static void Main(string[] args) 25 { 26 string longName = "Roslynator.Core, Version=2.1.0.1, Culture=neutral, PublicKeyToken=926ea54d246a765e"; 27 Assembly assem = Assembly.Load(longName); 28 if (assem == null) 29 Console.WriteLine("Unable to load assembly..."); 30 else 31 Console.WriteLine(assem.FullName); 32 } 33 } 34 }