Why does adding permissions to an existing AppDomain have no effect?
Posted
by MainMa
on Stack Overflow
See other posts from Stack Overflow
or by MainMa
Published on 2010-05-26T01:03:24Z
Indexed on
2010/05/26
1:21 UTC
Read the original article
Hit count: 301
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?
© Stack Overflow or respective owner