how to serialize/deserialize an assembly object to and from a byte array

后端 未结 4 839
予麋鹿
予麋鹿 2020-12-18 08:59

Let\'s say a create an (executable) assembly in memory by compiling a code string. Then I want to serialize this assembly object into a byte array and then store it in a da

4条回答
  •  孤城傲影
    2020-12-18 09:46

    An assembly is more conveniently represented simply as a binary dll file. If you think of it like that, the rest of the problems evaporate. In particlar, look at Assembly.Load(byte[]) for loading an Assembly from binary. To write it as binary, use CompileAssemblyFromSource and look at the result's PathToAssembly - then File.ReadAllBytes(path) to obtain the binary from the file.

提交回复
热议问题