• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

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

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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]

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978709

• 21
• 14
• 12
• 10
• 12