Jul
31
2009

In .NET 4.0 SecurityManager.IsGranted is obsolete

In .NET 4.0 SecurityManager.IsGranted has been made obsolete.  This is what it was and if you compile in .NET 4.0 compatibility it will complain.

bool isGranted = SecurityManager.IsGranted(new SecurityPermission(SecurityPermissionFlag.Infrastructure))

In order to fix this now you have to do this instead.

var permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
bool isGranted = permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);

Comments (2) -

abdox2

Thank you for sharing

Ed

way to go Microsoft! make us use 3 lines of code when we used to be able to do it in 1. Microsoft quality, at it again.

thanks for the explanation. i downloaded a project and needed to convert it to the new un-obsoleted version.