Getting crazy with Deny()
-
I WANT make it clear that i dont want the highlighted code to run but it does, can make someone tell me why? the permissions (intersecting all policy levels) for the assembly are unrestricted access to reflection. I checked it myself. I'm sure there is no mistake in the policy configurations using System; using System.Reflection; using System.Security; using System.Security.Permissions; [assembly:ReflectionPermissionAttribute(SecurityAction.RequestRefuse,Unrestricted=true, Flags = ReflectionPermissionFlag.AllFlags)] namespace reflectsecuritytest { public class mo { public static void met( int i ) { } public static void met( float f ) { } public static void met( string s ) { } public static int met( decimal d ) { return 1; } public static void met( object o ) { } public int i = 9; public static int x = 2; private int pr { get { return 2; } } } [ ReflectionPermissionAttribute( SecurityAction.Deny, Flags = ReflectionPermissionFlag.AllFlags, Unrestricted = true ) ] class Class1 { public static void PermisosReflect() { ReflectionPermission sec = new ReflectionPermission( ReflectionPermissionFlag.AllFlags ); try { sec.Deny(); //************************* //************************* // ********************************* // the next code is supposed not to execute, but it does //************************* //************************* //************************* Type t = typeof( mo ); BindingFlags bf = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; foreach( MemberInfo mi in t.GetMembers( bf ) ) { Console.WriteLine( mi ); }; } catch( SecurityException e ){ Console.WriteLine( e ); } } public static void Deny() { Console.WriteLine("before calling"); ReflectionPermission sec = new ReflectionPermission( ReflectionPermissionFlag.AllFlags ); sec.Deny(); PermisosReflect();