SecurityException when Remote Debugging with VS2005 May 31, 2007
Posted by codinglifestyle in Security.Tags: assembly, remote debugging, Security, security policy, SecurityException, strong name, trust
add a comment
You may run in to a situation where you are remote debugging an application (a simple console program in my case) and receive a security exception like this:
System.Security.SecurityException was unhandled
Message: Request for the permission of type ‘Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ failed.
The interesting thing was the program executed properly when run directly on the server. However, when run via the remote debugger the problem cropped up. I figured .NET v2 Configuration Manager was the right place to fix the problem but we no longer have the wizard which includes “Trust an assembly”. Before finding the solution I did try caspol.exe –af file.exe but this did not work. Finally I found the solution as follows:
- Strongly name your assembly
- Open ‘.NET Framework 2.0 Configuration’ from Administrative Tools
- Under Runtime Security Policy->Enterprise->Code Groups->All_Code right click and select New
- Give the new Code Group a name and description and click Next
- Select Strong Name as the condition type
- Press the Import button to import the Public Key and click Next
- Click Finish to create the code group
- Edit the properties of the newly created group
- Ensure the ‘Policy levels below this level will not be evaluated’ is checked
You should now be able to remotely debug any program strongly named with the specified public key.