Re: Compile assembly in runtime and execute in sandbox
From: Henning Krause [MVP] (newsgroup.no_at_spam.infinitec.de)
Date: 02/26/05
- Previous message: Paul Hatcher: "Re: Medium Level Trust and Reflection"
- In reply to: JFN: "Compile assembly in runtime and execute in sandbox"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Sat, 26 Feb 2005 10:22:22 +0100
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@ipmouse.com> wrote in message
news:OtQ8l44GFHA.904@tk2msftngp13.phx.gbl...
> 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.dll");
>
>
compilerParams.ReferencedAssemblies.Add(Path.Combine(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
>
>
>
>
- Previous message: Paul Hatcher: "Re: Medium Level Trust and Reflection"
- In reply to: JFN: "Compile assembly in runtime and execute in sandbox"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|