I'm trying to create a sandboxed appdomain. It isn't to difficult so far. I just came across one problem I couldn't seem to fix:
This is a shortened version of my classes, but you should get the idea:
public class LocalLoader : CrossAppDomainObject
{
public LocalLoader()
{
RemoteLoader remoteloader;
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationName = "MyAppDomain";
setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
PermissionSet permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
appdomain = AppDomain.CreateDomain("MyAppDomain", AppDomain.CurrentDomain.Evidence, setup, permissions, null);
remoteloader = (RemoteLoader)appdomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(RemoteLoader).FullName);
}
}
public class RemoteLoader: CrossAppDomainObject
{
}
The
CrossAppDomainObject
is simply put a class which inherits
MarshalByRefObject
and overrides the
InitializeLifetimeService()
method. Like this (also shortened):
public abstract class CrossAppDomainObject : MarshalByRefObject
{
public sealed override object InitializeLifetimeService()
{
return null;
}
}
It will cause the lifetime of the connection to be infinite, a must have in my project.
When I do the
appdomain.CreateInstanceAndUnwrap
I receive this error:
Inheritance security rules violated while overriding member: 'MyApplication.CrossAppDomainObject.InitializeLifetimeService()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
I've looked around for settings I should allow in my
PermissionSet
but I couldn't find anything that worked. Or should I add additional things to my
CrossAppDomainObject
?
Anyone an idea how I should fix this?
Answers are much appreciated.