tags:

views:

62

answers:

2

I am trying to save an Assembly to a file using System.Reflection.Emit.AssemblyBuilder but it's not working.

I've got a variable to hold an assembly that is running perfect when I load and run it.

System.Reflection.Assembly dll = GetAssembly(resource);

Is there anyone who can help me to save this "dll" into a file like "name.dll"?

A: 

Your AssemblyBuilderAccess flags must be RunAndSave or Save for it to work.

leppie
+1  A: 

In the comments, you've said that the private GetAssembly method fetches data from a resource file and builds an assembly from it. Assuming the "bytes" it's getting from the resource file really are just the bytes of the assembly, the simplest way of getting a file is to get those same bytes from the resource file, and call File.WriteAllBytes. You don't need to go via an Assembly object, and doing so makes the job harder.

Jon Skeet