Opposite operation to Assembly Load(byte[] rawAssembly)

前端 未结 3 884
庸人自扰
庸人自扰 2021-02-14 22:37

I notice that there is a method of System.Reflection.Assembly, which is Assembly Load(byte[] rawAssembly).

I wonder if there is an opposite ope

3条回答
  •  粉色の甜心
    2021-02-14 23:00

    System.Reflection.Assembly implements ISerializable. Create an instance of BinaryFormatter and call its Serialize method on any stream - MemoryStream, FileStream, etc.

    Assembly yourAssembly;
    var formatter = new BinaryFormatter();
    var ms = new MemoryStream();
    formatter.Serialize(ms, yourAssembly);
    var reloadedAssembly = Assembly.Load(ms.GetBuffer()); 
    

提交回复
热议问题