mercredi 25 novembre 2015

Attach in-memory assembly in custom AppDomain

I have created a sandbox AppDomain:

public AppDomain CreateSandbox()
{
    var setup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase };
    var permissionSet = new PermissionSet(PermissionState.None);
    permissionSet.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.NoFlags));
    permissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
    permissionSet.AddPermission(new FileIOPermission(PermissionState.Unrestricted)); // TODO: Restrict IO
    var appDomain = AppDomain.CreateDomain("Sandbox", null, setup, permissionSet);
    return appDomain;
}

I also have an assembly loaded from a byte[] fileData:

var assembly = Assembly.Load(fileData);
var appDomain = CreateSandBox();

How can I load this assembly or the fileData bytes into the appDomain and then use it?





Aucun commentaire:

Enregistrer un commentaire