SecurityManager deprecated API in .NET 4.0
While I was upgrading Castle Windsor to support .NET 4.0 build scripts, I came across an interesting deprecated API. If you have set Warnings are Errors in your project settings, you’ll definitely get bitten by this once you upgrade your project from .NET 3.5 to .NET 4.0, if you’re using SecurityManager that is.
Let’s say you want to check for Unmanaged Code permission. In .NET 3.5 you’d do it like this:
return SecurityManager.IsGranted(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
But this construct is deprecated in .NET 4.0. What you can do is to create a PermissionSet and compare it to the one on the current AppDomain. In case you need to support both versions of the .NET Framework, you still should use the old API:
private static bool CanAccessCredentials