Why does adding permissions to an existing AppDomain have no effect?
- by MainMa
Hi,
I have a following code which behaves strangely in .NET 4.0:
// AppDomain is created, and permissions which were added to `sandboxPermissions` are added successfully.
sandboxAppDomain = AppDomain.CreateDomain("SandboxDomain", null, appDomainSetup, sandboxPermissions, new[] { commonStrongName });
// Trying to add a new permission to an AppDomain which is already created.
sandboxAppDomain.PermissionSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, @"C:\Some\Path\Here"));
// Setting breakpoint to this line: `permissions` contains every permission which was added to `sandboxPermissions`, but no trace of C:\Some\Path\Here related permission.
var permissions = sandboxAppDomain.PermissionSet.ToXml();
Every permission added before creating an AppDomain is just here, as expected. But adding permissions after an AppDomain is created has no effect at all.
There are no exceptions thrown (nor first-chance ones).
What can it be? If the framework method (AddPermission) fails to do what it was expected to do, mustn't it throw an exception?