开发者

Compiled in memory Assembly object to bytes[]

开发者 https://www.devze.com 2023-03-27 06:27 出处:网络
I am generate assembly object in memory and need to get it byte representation. I\'ve following code but today I need that it to be done in memory

I am generate assembly object in memory and need to get it byte representation. I've following code but today I need that it to be done in memory

var assembly = GetMyAssembly();
var binary = File.ReadAllBytes(assembly.Location);

I've looked into Assembly builder m开发者_如何学Cethods and Assembly methods but can't find appropriate methods.

Thanks.


I'm not sure about saving straight to a byte[], but you can save a dynamic assembly (defined using AssemblyBuilder), using AssemblyBuilder.Save, and then load it using File.ReadAllBytes. You can create it in a temporary directory, and delete it when you're done.

Hope that helps.


This is not possible in the runtime.

The only possible solution is to use WinDbg and SOS to dump the assembly. But then again, all my attempts at doing that exact same thing has failed.

0

精彩评论

暂无评论...
验证码 换一张
取 消