When to revertAccess() for code access permission

Do I need to revert access in my catch block before the error is thrown here? What happens if I don’t? I don’t completely understand the purpose of asserting permissions…

perm = new InteropPermission(interopKind::ClrInterop);

perm.assert();

try

{

// Do code

}

catch

{

throw error (“My error”);

}

CodeAccessPermission::revertAccess();

Hi,

you can write like i have shown below.

try

{

// Do code

//last line of try//–> CodeAccessPermission::revertAccess();

}

catch

{

//berfore throw error//–>CodeAccessPermission::revertAccess();

throw error (“My error”);

}

I know I can do that. But do I have to? Does permission revert automatically?

You must call Assert method before invoking any secured API.

see the list of secured API’s http://msdn.microsoft.com/en-us/library/aa852189.aspx

see more about the asser() http://msdn.microsoft.com/en-us/library/aa655056.aspx