In-Memory Assemblies: Stuck in Generating AppDomain?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I want to use CompileAssemblyFromSource to create an assembly on the fly,
then I want to run it in a separate AppDomain. The separate AppDomain will
have tight security permissions.

Is there any way to compile an assembly in Domain A, then execute it in
domain B, _without_ persisting it to disk?

The answer seems to be "no" - in which case what is the point of the
GenerateInMemory flag? If you can generate in memory but then cannot run in
a separate domain, what's the point?
 
Generate in memory simply specifies whether the assembly is loaded into
memory or not after compilation .. It still saves the assembly to a temp
file when doing the compilation.

I had some confusion over this as well as it seems things are not
appropriately named ...

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
 
With generate in memory then, does it immediately delete the temp file, after
it loads the assembly?

John
 
Thanks for your help Greg.

I've decided to generate to disk, then immediately load the generated
assembly into memory as a byte[], load that byte[] into my target app domain
(with Assembly.Load()), and then delete the disk file straight away. (So I
don't have to clean up the disk file later, when the AppDomain shuts down).
That works satisfactorily in my testing so far.

John
 
Back
Top