Re: Strange behavior or where is SecurityException?
- From: "Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com>
- Date: Wed, 14 Jun 2006 12:37:16 -0400
I'm guessing that this is running against fx 2.0. If so, it might help to
be know that ReflectionPermission no longer protects access to non-public
member metadata. However, it does still protect use of non-public members.
If you were to try to read the value of the private field from an instance
of the type, you should see the SecurityException you expect.
HTH,
Nicole
"Sneil" <at@xxxxxxx> wrote in message
news:ugl0c%233jGHA.2004@xxxxxxxxxxxxxxxxxxxxxxx
Just simple code:
using System;
using System.Reflection;
using System.Security.Permissions;
[assembly : ReflectionPermission(SecurityAction.RequestRefuse,
Flags=ReflectionPermissionFlag.AllFlags)]
namespace UseReflect
{
public class Program
{
public static void Main(string[] args)
{
Assembly ClientAssembly =
Assembly.LoadFrom(@"c:\VSprojects\secur\JustLib\JustLib\bin\Debug\JustLi
b.dll");
Type myT = ClientAssembly.GetType("JustLib.MyLib");
// Accessing private members requires Reflection Permission
FieldInfo myFI = myT.GetField("f1", BindingFlags.NonPublic
| BindingFlags.Instance);
if(myFI != null)
Console.WriteLine("Field: {0} Type: {1}", myFI.Name,
myFI.FieldType);
else
Console.WriteLine("You don't have enough rights!");
Console.ReadKey();
}
}
}
And it's work without problem - no exceptions! But why? I
reject(RequestRefuse) all reflection activity for this assembly, but is
still work. Draw attention to - I don't want prevent other(third-party)
assembly to reflect my code. I only want prevent MY OWN code(because of
bug, for example) do reflect things. Am I missing something?
.
- Follow-Ups:
- References:
- Strange behavior or where is SecurityException?
- From: Sneil
- Strange behavior or where is SecurityException?
- Prev by Date: Re: Mapping AZMAN to our existing security Design, Scenario?
- Next by Date: Re: Custom CAS permission...
- Previous by thread: Strange behavior or where is SecurityException?
- Next by thread: Re: Strange behavior or where is SecurityException?
- Index(es):
Relevant Pages
|