c# - Understanding AppDomains and strong naming -
i'm trying create sandbox can load plugins. create appdomain
, specify strongname
host assembly, , understanding code running in assembly named runs in full trust. seems not case.
example,
static void main(string[] args) { var permissions = new permissionset(permissionstate.none); var setup = new appdomainsetup() { applicationbase = "c:\\temporary\\sandbox" }; var domain = appdomain.createdomain("sandbox", null, setup, permissions, typeof (pluginhost).assembly.evidence.gethostevidence<strongname>()); var handle = activator.createinstancefrom(domain, typeof (pluginhost).assembly.manifestmodule.fullyqualifiedname, typeof (pluginhost).fullname); var host = (pluginhost) handle.unwrap(); host.runplugin(); }
pluginhost (defined in same assembly i'm strong naming),
public class pluginhost : marshalbyrefobject { public void runplugin() { file.readalltext("c:\\passwords.txt"); var asm = assembly.loadfile(@"c:\plugins\unsafeplugin.dll"); var t = asm.gettype("unsafeplugin.fooplugin"); object plugin = activator.createinstance(t); plugin.gettype().getmethod("run").invoke(plugin, null); } }
and plugin (residing in external assembly)
public class fooplugin { public void run() { file.readalltext("c:\\passwords.txt"); } }
i strong naming assembly containing pluginhost
, therefore expect able read passwords file pluginhost
, not fooplugin
code throws securityexception
when reading file (in pluginhost
).
my understanding msdn documentation on subject fourth parameter containing strongname-instances give assemblies full trust in application domain.
from documentation:
"an array of strong names representing assemblies considered trusted in new application domain."
since proved myself wrong - how supposed work? why not in full trust though i've passed strongname
appdomain.create
?
Comments
Post a Comment