Re: Compile assembly in runtime and execute in sandbox

From: Shawn Farkas [MS] (shawnfa_at_online.microsoft.com)
Date: 03/02/05


Date: Wed, 02 Mar 2005 17:08:52 GMT

Glad to help out. Figuring out those loader issues can be a pain the
first time around, but once you get a hang of things they all follow a
pretty basic set of rules.

-Shawn
http://blogs.msdn.com/shawnfa
--
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Note:
For the benefit of the community-at-large, all responses to this message
are best directed to the newsgroup/thread from which they originated.
--------------------
> From: "JFN" <andre@ipmouse.com>
> References: <OtQ8l44GFHA.904@tk2msftngp13.phx.gbl>
<TfFB#T6GFHA.3084@TK2MSFTNGXA02.phx.gbl>
<eO#OcrEHFHA.3156@TK2MSFTNGP10.phx.gbl>
<K2Tk8HeHFHA.3888@TK2MSFTNGXA02.phx.gbl>
<##X8LYhHFHA.1396@TK2MSFTNGP10.phx.gbl>
<6n0x8#rHFHA.1140@TK2MSFTNGXA02.phx.gbl>
> Subject: Re: Compile assembly in runtime and execute in sandbox
> Date: Tue, 1 Mar 2005 20:41:50 -0600
> Lines: 131
> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 6.00.2800.1478
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1478
> Message-ID: <e31W4EtHFHA.3336@TK2MSFTNGP10.phx.gbl>
> Newsgroups: microsoft.public.dotnet.security
> NNTP-Posting-Host: adsl-68-89-47-207.dsl.hstntx.swbell.net 68.89.47.207
> Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1
0.phx.gbl
> Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.security:9296
> X-Tomcat-NG: microsoft.public.dotnet.security
>
>
> Hey, too bad I only read your answer tonight.
> Spend ~4 hours today trying to figure it out WTF is going on. I have found
> her blog and this particular entry,
> which helped me finally understood that is it my main domain couldn't find
> new assembly, not a new one,
> after that rest was piece of cake.
> Anyway, thanks a lot for the hints,
>
> regards,
> Ken
>
> ""Shawn Farkas [MS]"" <shawnfa@online.microsoft.com> wrote in message
> news:6n0x8%23rHFHA.1140@TK2MSFTNGXA02.phx.gbl...
> > Sure do :-) The directory you want to put the generated assemblies in
> > needs to be located under the directory your application is executing in
> > (or more precisely the AppBase directory). I recommend reading Suzanne
> > Cook's blog for information about the loader
> > (http://blogs.msdn.com/suzcook). Specifically
> > http://blogs.msdn.com/suzcook/archive/2003/05/29/57120.aspx for help
> > debugging load failures.
> >
> > -Shawn
> > http://blogs.msdn.com/shawnfa
> > --
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> >
> >
> > Note:
> > For the benefit of the community-at-large, all responses to this message
> > are best directed to the newsgroup/thread from which they originated.
> > --------------------
> > > From: "JFN" <andre@ipmouse.com>
> > > References: <OtQ8l44GFHA.904@tk2msftngp13.phx.gbl>
> > <TfFB#T6GFHA.3084@TK2MSFTNGXA02.phx.gbl>
> > <eO#OcrEHFHA.3156@TK2MSFTNGP10.phx.gbl>
> > <K2Tk8HeHFHA.3888@TK2MSFTNGXA02.phx.gbl>
> > > Subject: Re: Compile assembly in runtime and execute in sandbox
> > > Date: Mon, 28 Feb 2005 22:22:10 -0600
> > > Lines: 61
> > > X-Priority: 3
> > > X-MSMail-Priority: Normal
> > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1478
> > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1478
> > > Message-ID: <##X8LYhHFHA.1396@TK2MSFTNGP10.phx.gbl>
> > > Newsgroups: microsoft.public.dotnet.security
> > > NNTP-Posting-Host: adsl-68-89-47-207.dsl.hstntx.swbell.net
68.89.47.207
> > > Path:
> >
>
TK2MSFTNGXA02.phx.gbl!TK2MSFTCMTY1.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP0
> > 8.phx.gbl!TK2MSFTNGP10.phx.gbl
> > > Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.security:9280
> > > X-Tomcat-NG: microsoft.public.dotnet.security
> > >
> > >
> > > ""Shawn Farkas [MS]"" <shawnfa@online.microsoft.com> wrote in message
> > > news:K2Tk8HeHFHA.3888@TK2MSFTNGXA02.phx.gbl...
> > > > You'd need to make the objects that interface between the AppDomains
> > > derive
> > > > from MarshalByRefObject. Here's some information that shows how to
> > setup
> > > a
> > > > sandboxed domain:
> > > > http://blogs.msdn.com/shawnfa/archive/2004/10/25/247379.aspx
> > >
> > > I have figured out part of puzzle today - was able to create domain,
> > > compile signed assembly on fly,
> > > add "AllowPartiallyTrustedCallers" attribute to my main assemblies,
and
> > pass
> > > my objects as parameters.
> > > And permission set for my public key that I set up in .NET security
> > applied.
> > > Thank you for help.
> > >
> > > One more thing I run into while trying to make production code out of
> test
> > > rig.
> > > I cannot load this new temporary assembly to new AppDomain from temp
> > folder.
> > >
> > > I.e. when I use output name for temp assembly in my bin folder,
> everything
> > > works
> > >
> > > CompilerParameters compilerParams = new CompilerParameters();
> > >
> >
>
compilerParams.ReferencedAssemblies.Add(Path.Combine(Application.StartupPath
> > > , "MyCompany.MyFramework.dll"));
> > > compilerParams.OutputAssembly = Path.Combine(Application.StartupPath,
> > > "foo.dll"));
> > >
> > > macroDomain.CreateInstanceFromAndUnwrap(compilerParams.OutputAssembly,
> > > "MyClass.Bar");
> > >
> > > For many reasons, I don't want to write into application folder. So, I
> > need
> > > to use temp one.
> > >
> > > compilerParams.OutputAssembly = Application.GetTempFileName();
> > > //Yes, I know it does using temp file by default, just want to make
> sample
> > > clear.
> > >
> > > Then when I'm trying to load it, I keep getting "cannot find assembly
or
> > > referenced assembly" error
> > > (remember, compiled on the fly assembly references 2 assemblies from
my
> > > application folder)
> > > I have created AppDomain using AppDomainSetup class, with different
> > > combinations of ApplicationBase, PrivetBinPath
> > > pointed to my application and temp folders, even tried to load
> referenced
> > > assemblies to new domain manually, but
> > > nothing works.
> > > Any ideas?
> > >
> > > regards,
> > > Ken
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
>
>
>


Quantcast