One of my least favorite errors when I first ran Static Code Analsysis was this security warning:
CA2209 : Microsoft.Usage : No valid permission requests were found for assembly 'IKRulz'. You should always specify the minimum security permissions using SecurityAction.RequestMinimum.
So what is the solution to this warning, and where in the heck do I set these permissions. Well under .NET 2.0 you need an application manifiest (app.manifiest) file as part of your project settings. The application manifest basically tells the CLR what type of security your application expects to need, so for example if your application requires full trust your app.manifest will look something like:
<?xml version="1.0" encoding="utf-8"?> <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <applicationRequestMinimum> <defaultAssemblyRequest permissionSetReference="Custom" /> <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" /> </applicationRequestMinimum> </security> </trustInfo> </asmv1:assembly>
Which is of course a totally simple thing to figure out right? OK, so does this mean you need to start going to all your app files and adding what are best described as some somewhat obscure XML properties to define your apps security settings. Well no not under Visual Studio 2005. With VIsual Studio 2005 you can simply go to your project properties and there on the edit pane is a right hand panel for Security, as you can see below:
Now that you are on the security pane you can choose to enable your ClickOnce security settings. This will generate your App.Manifest automatically.
But wait there's more. As you'll probably see in every demo with Visual Studio 2005 it is possible to mark your assembly as having less then full rights. The key to this is the "Calculate Permissions" button you see above. This button compiles your code and using reflection determines what permission level your code actually needs. In my case the code references local files system files, and therefore requires full trust. However, the ClickOnce options allow you to determine that on the fly and have Visual Studio 2005 automatically determine whether your application will meet your deployment model.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.