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.
精彩评论