Creating an assembly in memory

I would like to create an assembly in memory using classes in Reflection.Emit

Currently, I can create an assembly and get its bytes using something like

AssemblyBuilder builder =
   AppDomain.CurrentDomain.DefineDynamicAssembly(..., 
      AssemblyBuilderAccess.Save);

... create the assembly ...

builder.Save(targetFileName);

using(FileStream fs = File.Open(targetFileName, FileMode.Open))
{
   ... read the bytes from the file stream ...
}

However, he does this by creating a file on the local file system. I really don't need the file, just the bytes that will be in the file.

Is it possible to create an assembly without writing any files?

+3
source share
2 answers

This is not possible at the moment. The C # team is planning a compiler as a service feature, which I hope will be included in C # 5.0.

+3
source

What about a call AssemblyBuilder.GetObjectDatathat gives you serialized assembly data rather than looking for bytes? This is probably good enough.

MSDN: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getobjectdata.aspx

..::. GetObjectData​​strong >
, .

0

Source: https://habr.com/ru/post/1749867/


All Articles