HighTechTalks DotNet Forums  

Compile assembly in runtime and execute in sandbox

Dotnet Security microsoft.public.dotnet.security


Discuss Compile assembly in runtime and execute in sandbox in the Dotnet Security forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
JFN
 
Posts: n/a

Default Compile assembly in runtime and execute in sandbox - 02-25-2005 , 06:04 PM






Hello,

I'm trying to use C# as a script language for my .NET application.
Users able to write a method (say, Foo(Myclass parameter))
Then in run time I'm wrapping this method into namespace code, compile into
assembly signed with special key and execute.

Here is a problem - I'd like to apply some restrictions on user's code.
I.e. "Internet" set of permissions.

But it doesn't work. When I create code group for this special key, any
permission set besides "Full trust" gives me
"Security error". Even "Everything" set. I have "This policy level"
checkbox in Code Group properties dialog checked (if it not checked then
compiled assembly got all permissions from main application)
So, is it possible at all? Am I doing something wrong or may be just don't
understand something about security model?

Please, help!

Here is code snippet

CodeDomProvider provider = new CSharpCodeProvider();
ICodeCompiler compiler = provider.CreateCompiler();
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.GenerateInMemory = false;
compilerParams.ReferencedAssemblies.Add("System.dl l");

compilerParams.ReferencedAssemblies.Add(Path.Combi ne(Application.StartupPath
, "MyCompany.MyFramework.dll"));

string code = "[assembly: AssemblyKeyName(\"MyKey\")]";
code += myNamespaceAndMethodText;

CompilerResults results =
compiler.CompileAssemblyFromSource(compilerParams, code);
object o = results.CompiledAssembly.CreateInstance("MyClass", true);

//this is where Security exception throws:
object retVal = o.GetType().InvokeMember("Foo", new object[]
{myClassInstance});


regards,
Ken





Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default RE: Compile assembly in runtime and execute in sandbox - 02-25-2005 , 08:46 PM






Hi Ken,

This sounds to me like you might be running into APTCA. Is the exception
occuring when the newly compiled code calls back into code that you've
provided with your application? Check out:
http://blogs.msdn.com/shawnfa/archiv...04/367390.aspx for more
information about APTCA.

Also, you didn't say in your post, but if you really want to be secure
about things, you should be loading the assemblies you compile into a
seperate AppDomain which also has Internet evidence applied, in order to
isolate them from the rest of yoru system.

-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.
--------------------
Quote:
From: "JFN" <andre (AT) ipmouse (DOT) com
Subject: Compile assembly in runtime and execute in sandbox
Date: Fri, 25 Feb 2005 17:04:10 -0600
Lines: 49
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: <OtQ8l44GFHA.904 (AT) tk2msftngp13 (DOT) phx.gbl
Newsgroups:
microsoft.public.dotnet.framework.clr,microsoft.pu blic.dotnet.security
NNTP-Posting-Host: adsl-68-89-46-70.dsl.hstntx.swbell.net 68.89.46.70
Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGP08.phx.gbl!tk2msftngp1
3.phx.gbl
Quote:
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.security:9246
microsoft.public.dotnet.framework.clr:12984
X-Tomcat-NG: microsoft.public.dotnet.security

Hello,

I'm trying to use C# as a script language for my .NET application.
Users able to write a method (say, Foo(Myclass parameter))
Then in run time I'm wrapping this method into namespace code, compile
into
assembly signed with special key and execute.

Here is a problem - I'd like to apply some restrictions on user's code.
I.e. "Internet" set of permissions.

But it doesn't work. When I create code group for this special key, any
permission set besides "Full trust" gives me
"Security error". Even "Everything" set. I have "This policy level"
checkbox in Code Group properties dialog checked (if it not checked then
compiled assembly got all permissions from main application)
So, is it possible at all? Am I doing something wrong or may be just
don't
understand something about security model?

Please, help!

Here is code snippet

CodeDomProvider provider = new CSharpCodeProvider();
ICodeCompiler compiler = provider.CreateCompiler();
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.GenerateInMemory = false;
compilerParams.ReferencedAssemblies.Add("System.dl l");


compilerParams.ReferencedAssemblies.Add(Path.Combi ne(Application.StartupPath
, "MyCompany.MyFramework.dll"));

string code = "[assembly: AssemblyKeyName(\"MyKey\")]";
code += myNamespaceAndMethodText;

CompilerResults results =
compiler.CompileAssemblyFromSource(compilerParams, code);
object o = results.CompiledAssembly.CreateInstance("MyClass",
true);

//this is where Security exception throws:
object retVal = o.GetType().InvokeMember("Foo", new object[]
{myClassInstance});


regards,
Ken







Reply With Quote
  #3  
Old   
Henning Krause [MVP]
 
Posts: n/a

Default Re: Compile assembly in runtime and execute in sandbox - 02-26-2005 , 04:22 AM



Hello,

I'm not very proficient on this topic, but I believe you should load the
newly created type into another app domain and execute it there.

The new app domain can be initialized with a custom set of evidence.

Greetings,
Henning Krause [MVP]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


"JFN" <andre (AT) ipmouse (DOT) com> wrote

Quote:
Hello,

I'm trying to use C# as a script language for my .NET application.
Users able to write a method (say, Foo(Myclass parameter))
Then in run time I'm wrapping this method into namespace code, compile
into
assembly signed with special key and execute.

Here is a problem - I'd like to apply some restrictions on user's code.
I.e. "Internet" set of permissions.

But it doesn't work. When I create code group for this special key, any
permission set besides "Full trust" gives me
"Security error". Even "Everything" set. I have "This policy level"
checkbox in Code Group properties dialog checked (if it not checked then
compiled assembly got all permissions from main application)
So, is it possible at all? Am I doing something wrong or may be just
don't
understand something about security model?

Please, help!

Here is code snippet

CodeDomProvider provider = new CSharpCodeProvider();
ICodeCompiler compiler = provider.CreateCompiler();
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.GenerateInMemory = false;
compilerParams.ReferencedAssemblies.Add("System.dl l");


compilerParams.ReferencedAssemblies.Add(Path.Combi ne(Application.StartupPath
, "MyCompany.MyFramework.dll"));

string code = "[assembly: AssemblyKeyName(\"MyKey\")]";
code += myNamespaceAndMethodText;

CompilerResults results =
compiler.CompileAssemblyFromSource(compilerParams, code);
object o = results.CompiledAssembly.CreateInstance("MyClass",
true);

//this is where Security exception throws:
object retVal = o.GetType().InvokeMember("Foo", new object[]
{myClassInstance});


regards,
Ken







Reply With Quote
  #4  
Old   
JFN
 
Posts: n/a

Default Re: Compile assembly in runtime and execute in sandbox - 02-26-2005 , 04:35 PM




""Shawn Farkas [MS]"" <shawnfa (AT) online (DOT) microsoft.com> wrote


Quote:
This sounds to me like you might be running into APTCA. Is the exception
occuring when the newly compiled code calls back into code that you've
provided with your application? Check out:
http://blogs.msdn.com/shawnfa/archiv...04/367390.aspx for more
information about APTCA.
Thank you, this is may be it. I'll try at Monday

Quote:
Also, you didn't say in your post, but if you really want to be secure
about things, you should be loading the assemblies you compile into a
seperate AppDomain which also has Internet evidence applied, in order to
isolate them from the rest of yoru system.
I havn't done that before. Any code snippets? Also, how would it work with
objects from main AppDomain?
I need to pass quite a bit information to those compiled methods.

regards,
Ken




Reply With Quote
  #5  
Old   
AT
 
Posts: n/a

Default Re: Compile assembly in runtime and execute in sandbox - 02-28-2005 , 05:08 PM



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/archiv...25/247379.aspx


-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.
--------------------
Quote:
From: "JFN" <andre (AT) ipmouse (DOT) com
References: <OtQ8l44GFHA.904 (AT) tk2msftngp13 (DOT) phx.gbl
TfFB#T6GFHA.3084 (AT) TK2MSFTNGXA02 (DOT) phx.gbl
Subject: Re: Compile assembly in runtime and execute in sandbox
Date: Sat, 26 Feb 2005 15:35:04 -0600
Lines: 25
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: <eO#OcrEHFHA.3156 (AT) TK2MSFTNGP10 (DOT) 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!cpmsftngxa10.phx.gbl!TK2MSFT FEED02.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP10.phx.gbl
Quote:
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.security:9266
X-Tomcat-NG: microsoft.public.dotnet.security


""Shawn Farkas [MS]"" <shawnfa (AT) online (DOT) microsoft.com> wrote in message
news:TfFB%

This sounds to me like you might be running into APTCA. Is the
exception
occuring when the newly compiled code calls back into code that you've
provided with your application? Check out:
http://blogs.msdn.com/shawnfa/archiv...04/367390.aspx for more
information about APTCA.

Thank you, this is may be it. I'll try at Monday

Also, you didn't say in your post, but if you really want to be secure
about things, you should be loading the assemblies you compile into a
seperate AppDomain which also has Internet evidence applied, in order to
isolate them from the rest of yoru system.

I havn't done that before. Any code snippets? Also, how would it work
with
objects from main AppDomain?
I need to pass quite a bit information to those compiled methods.

regards,
Ken





Reply With Quote
  #6  
Old   
JFN
 
Posts: n/a

Default Re: Compile assembly in runtime and execute in sandbox - 02-28-2005 , 11:22 PM




""Shawn Farkas [MS]"" <shawnfa (AT) online (DOT) microsoft.com> wrote

Quote:
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/archiv...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.Combi ne(Application.StartupPath
, "MyCompany.MyFramework.dll"));
compilerParams.OutputAssembly = Path.Combine(Application.StartupPath,
"foo.dll"));

macroDomain.CreateInstanceFromAndUnwrap(compilerPa rams.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










Reply With Quote
  #7  
Old   
AT
 
Posts: n/a

Default Re: Compile assembly in runtime and execute in sandbox - 03-01-2005 , 07:35 PM



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/archiv.../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.
--------------------
Quote:
From: "JFN" <andre (AT) ipmouse (DOT) com
References: <OtQ8l44GFHA.904 (AT) tk2msftngp13 (DOT) phx.gbl
TfFB#T6GFHA.3084 (AT) TK2MSFTNGXA02 (DOT) phx.gbl
<eO#OcrEHFHA.3156 (AT) TK2MSFTNGP10 (DOT) phx.gbl>
<K2Tk8HeHFHA.3888 (AT) TK2MSFTNGXA02 (DOT) phx.gbl>
Quote:
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 (AT) TK2MSFTNGP10 (DOT) 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!TK2MSFT NGXA03.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP10.phx.gbl
Quote:
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.security:9280
X-Tomcat-NG: microsoft.public.dotnet.security


""Shawn Farkas [MS]"" <shawnfa (AT) online (DOT) microsoft.com> wrote in message
news:K2Tk8HeHFHA.3888 (AT) TK2MSFTNGXA02 (DOT) 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/archiv...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.Combi ne(Application.StartupPath
, "MyCompany.MyFramework.dll"));
compilerParams.OutputAssembly = Path.Combine(Application.StartupPath,
"foo.dll"));

macroDomain.CreateInstanceFromAndUnwrap(compilerPa rams.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











Reply With Quote
  #8  
Old   
JFN
 
Posts: n/a

Default Re: Compile assembly in runtime and execute in sandbox - 03-01-2005 , 09:41 PM




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 (AT) online (DOT) microsoft.com> wrote

Quote:
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/archiv.../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 (AT) ipmouse (DOT) com
References: <OtQ8l44GFHA.904 (AT) tk2msftngp13 (DOT) phx.gbl
TfFB#T6GFHA.3084 (AT) TK2MSFTNGXA02 (DOT) phx.gbl
eO#OcrEHFHA.3156 (AT) TK2MSFTNGP10 (DOT) phx.gbl
K2Tk8HeHFHA.3888 (AT) TK2MSFTNGXA02 (DOT) 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 (AT) TK2MSFTNGP10 (DOT) 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!TK2MSFT NGXA03.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 (AT) online (DOT) microsoft.com> wrote in message
news:K2Tk8HeHFHA.3888 (AT) TK2MSFTNGXA02 (DOT) 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/archiv...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.Combi ne(Application.StartupPath
, "MyCompany.MyFramework.dll"));
compilerParams.OutputAssembly = Path.Combine(Application.StartupPath,
"foo.dll"));

macroDomain.CreateInstanceFromAndUnwrap(compilerPa rams.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













Reply With Quote
  #9  
Old   
AT
 
Posts: n/a

Default Re: Compile assembly in runtime and execute in sandbox - 03-02-2005 , 12:08 PM



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.
--------------------
Quote:
From: "JFN" <andre (AT) ipmouse (DOT) com
References: <OtQ8l44GFHA.904 (AT) tk2msftngp13 (DOT) phx.gbl
TfFB#T6GFHA.3084 (AT) TK2MSFTNGXA02 (DOT) phx.gbl
<eO#OcrEHFHA.3156 (AT) TK2MSFTNGP10 (DOT) phx.gbl>
<K2Tk8HeHFHA.3888 (AT) TK2MSFTNGXA02 (DOT) phx.gbl>
<##X8LYhHFHA.1396 (AT) TK2MSFTNGP10 (DOT) phx.gbl>
<6n0x8#rHFHA.1140 (AT) TK2MSFTNGXA02 (DOT) phx.gbl>
Quote:
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 (AT) TK2MSFTNGP10 (DOT) 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!TK2MSF TNGP08.phx.gbl!TK2MSFTNGP1
0.phx.gbl
Quote:
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 (AT) online (DOT) microsoft.com> wrote in message
news:6n0x8%23rHFHA.1140 (AT) TK2MSFTNGXA02 (DOT) 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/archiv.../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 (AT) ipmouse (DOT) com
References: <OtQ8l44GFHA.904 (AT) tk2msftngp13 (DOT) phx.gbl
TfFB#T6GFHA.3084 (AT) TK2MSFTNGXA02 (DOT) phx.gbl
eO#OcrEHFHA.3156 (AT) TK2MSFTNGP10 (DOT) phx.gbl
K2Tk8HeHFHA.3888 (AT) TK2MSFTNGXA02 (DOT) 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 (AT) TK2MSFTNGP10 (DOT) 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!TK2MSFT NGXA03.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 (AT) online (DOT) microsoft.com> wrote in message
news:K2Tk8HeHFHA.3888 (AT) TK2MSFTNGXA02 (DOT) 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/archiv...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.Combi ne(Application.StartupPath
, "MyCompany.MyFramework.dll"));
compilerParams.OutputAssembly = Path.Combine(Application.StartupPath,
"foo.dll"));

macroDomain.CreateInstanceFromAndUnwrap(compilerPa rams.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















Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.