首先,为了动态的在内存中装载程序或程序集,我们以文件流的方式读取二进制文件,并将其以字节的形式保存在数组中,代码如下:

//动态加载插件

            String pluginFilePath = Path.GetDirectoryName(Application.ExecutablePath) +

                "\\plugins\\PluginLibrary.dll";

            FileStream fs = new FileStream(pluginFilePath, FileMode.Open);

            BinaryReader br = new BinaryReader(fs);

            byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length));

            fs.Close();

            br.Close();

然后,利用 Assembly 类的 Load 重载方法,以数组的形式加载该程序集。代码如下:
             Assembly assembly = Assembly.Load(bin);

转自:csharpwin

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2021-07-29
猜你喜欢
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
相关资源
相似解决方案