Home All Groups Group Topic Archive Search About

In-Memory Assemblies: Stuck in Generating AppDomain?

Author
29 Aug 2006 12:48 AM
John Rusk
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?

Author
29 Aug 2006 1:14 AM
Greg Young
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

Show quote
"John Rusk" <JohnR***@discussions.microsoft.com> wrote in message
news:86345C4E-B76A-4C7A-A17F-8B4279FEAEC5@microsoft.com...
> 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?
>
>
Author
29 Aug 2006 5:16 AM
John Rusk
With generate in memory then, does it immediately delete the temp file, after
it loads the assembly?

John

Show quote
"Greg Young" wrote:

> 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
>
> "John Rusk" <JohnR***@discussions.microsoft.com> wrote in message
> news:86345C4E-B76A-4C7A-A17F-8B4279FEAEC5@microsoft.com...
> > 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?
> >
> >
>
>
>
Author
29 Aug 2006 3:47 PM
Greg Young
Yes if output assembly is not given a real name ... I wanderred into this
out trying to generate an in memory reference
http://geekswithblogs.net/gyoung/archive/2006/04/27/76533.aspx

Cheers,

Greg

Show quote
"John Rusk" <JohnR***@discussions.microsoft.com> wrote in message
news:6B3E82D7-06DA-4678-8F0F-CA63294EE056@microsoft.com...
> With generate in memory then, does it immediately delete the temp file,
> after
> it loads the assembly?
>
> John
>
> "Greg Young" wrote:
>
>> 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
>>
>> "John Rusk" <JohnR***@discussions.microsoft.com> wrote in message
>> news:86345C4E-B76A-4C7A-A17F-8B4279FEAEC5@microsoft.com...
>> > 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?
>> >
>> >
>>
>>
>>
Author
30 Aug 2006 1:05 AM
John Rusk
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

Show quote
"Greg Young" wrote:

> Yes if output assembly is not given a real name ... I wanderred into this
> out trying to generate an in memory reference
> http://geekswithblogs.net/gyoung/archive/2006/04/27/76533.aspx
>
> Cheers,
>
> Greg
>
> "John Rusk" <JohnR***@discussions.microsoft.com> wrote in message
> news:6B3E82D7-06DA-4678-8F0F-CA63294EE056@microsoft.com...
> > With generate in memory then, does it immediately delete the temp file,
> > after
> > it loads the assembly?
> >
> > John
> >
> > "Greg Young" wrote:
> >
> >> 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
> >>
> >> "John Rusk" <JohnR***@discussions.microsoft.com> wrote in message
> >> news:86345C4E-B76A-4C7A-A17F-8B4279FEAEC5@microsoft.com...
> >> > 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?
> >> >
> >> >
> >>
> >>
> >>
>
>
>

AddThis Social Bookmark Button