I want to create an AppDomain and run an external WPF application through it. The main reason is security, as I would like to control what the external WPF app can do. Specifically, I want to disallow any usage of unmanaged code.
I've run the following code:
PermissionSet set = new PermissionSet(PermissionState.None);
set.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, PATH));
set.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
set.AddPermission(new UIPermission(PermissionState.Unrestricted));
set.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
Evidence ev = new Evidence();
AppDomain domain = AppDomain.CreateDomain("Test", ev, new AppDomainSetup() { ApplicationBase = PATH }, set);
domain.ExecuteAssembly(PATH);
and it works great.
When I remove the last line in the permission set (i.e., allowing the unmanaged code to run) it stops working.
How can I disallow the new app domain to run unmanaged code, but still have the WPF app run? (Btw, the WPF app is just a File->New WPF Application, so it doesn't use any unmanaged code).
Thanks!