Question for anyone using C# for scripting - or atleast Nypyren

Started by
2 comments, last by kspansel 20 years, 3 months ago
Is it possible to limit what namespaces/classes a script writer can have access to within a C# script? I know that it automatically references mscorlib.dll, which gives the script access to the System namespace but also the Reflection, IO, Microsoft.Win32, and some others. To me this seems a little strange. Kory Spansel "The pioneers of a warless world are the youth who refuse military service" - Albert Einstein
"The pioneers of a warless world are the youth who refuse military service" - Albert Einstein
Advertisement
If you''re worried about security you can limit your scripts from executing certain methods. Just give them partial trust instead of full trust. You can read up on this in MSDN.
Thanks for the reply. I realized like 5-minutes after I posted that I should check out the System.Security namespace, so I''ve been doing some research with that, and I think it''s exactly what I''m looking for. Thanks.

Kory Spansel

"The pioneers of a warless world are the youth who refuse military service" - Albert Einstein
"The pioneers of a warless world are the youth who refuse military service" - Albert Einstein
Okay, it turns out this is a little more complicated than I originally thought. I've read a bunch about how to set/get various permission for an assembly but all of the documentation refers to setting the permissions for the current assembly, which will not work for me. Then I tried to setup an AppDomain with the correct permissions, which worked ok, but I then ran into the problem of loading the assembly into that domain. I'm not sure how to load the assembly into the domain, because I'm dynamically compiling the assembly.

I keep getting a FileLoadException: The located assembly's manifest definition with name 'test_assembly' does not match the assembly reference.

Here's what I have:

I have already setup the AppDomain (scriptDomain) and CompileSourceFile is just a compiling helper method.

compilerParams.GenerateInMemory = true;compilerParams.GenerateExecutable = false;compilerParams.OutputAssembly = "test_assembly";		// Script NameAssembly compiledAssembly = CompileSourceFile( codeCompiler, compilerParams, scriptName );if( compiledAssembly != null ){	scriptDomain.Load( compiledAssembly.GetName( ) );	object scriptObject = compiledAssembly.CreateInstance( "ScriptTest1" );	MethodInfo scriptMethod = scriptObject.GetType( ).GetMethod( "ScriptTest" );	try	{		scriptMethod.Invoke( scriptObject, null );	}	catch( SecurityException ex )	{		Console.WriteLine( ex.Message );	}				}


"The pioneers of a warless world are the youth who refuse military service" - Albert Einstein

Damn Formatting!?!

[edited by - kspansel on January 23, 2004 5:48:51 AM]

[edited by - kspansel on January 23, 2004 5:49:57 AM]
"The pioneers of a warless world are the youth who refuse military service" - Albert Einstein

This topic is closed to new replies.

Advertisement