From 75e635dc2b8fd0a33dd9c075cac3a5491412a0d9 Mon Sep 17 00:00:00 2001 From: jfrijters Date: Sun, 31 May 2009 07:54:26 +0000 Subject: [PATCH] Doing a Demand probably makes a little more sense, although not a whole lot. An alternative could be to change the Create() method to distinguish between public, private and internal access and when internal access is requested explicitly look for the InternalsVisibleToAttribute on the target assembly to see if it grants us access, but that seems like a lot of complexity for what is essentially a special case (internal access). --- runtime/openjdk.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/runtime/openjdk.cs b/runtime/openjdk.cs index 8cf944d4..a410f176 100644 --- a/runtime/openjdk.cs +++ b/runtime/openjdk.cs @@ -271,8 +271,6 @@ namespace IKVM.Runtime static class DynamicMethodUtils { - private static bool? restrictedMemberAccess; - internal static DynamicMethod Create(string name, Type owner, bool nonPublic, Type returnType, Type[] paramTypes) { try @@ -305,11 +303,15 @@ static class DynamicMethodUtils { get { - if (!restrictedMemberAccess.HasValue) + try { - restrictedMemberAccess = System.Security.SecurityManager.IsGranted(new System.Security.Permissions.ReflectionPermission(System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess)); + new System.Security.Permissions.ReflectionPermission(System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess).Demand(); + return true; + } + catch (System.Security.SecurityException) + { + return false; } - return restrictedMemberAccess.Value; } } }