I have some simple VB code that subclasses a base class from another
assembly. The base class exposes an IDataReader via a protected field
named m_data.
When VB compiles the subclass, it has no problem accessing m_data from
it's base and executing the IDataReader methods even though the base
class is in another assembly.
Now, I am trying to duplicate the same thing using Reflection.Emit.
However, to emit IL to make calls against the field, I need to get a
reference to it.
Whenever I call GetField("m_data") it comes back as null.
I've also tried calling it with
BindingFlags.NonPublic|BindingFlags.Instance
The help states that I need to setup ReflectionPermission. However,
the help for that class is useless.
I've tried this code which makes me think that I have both
TypeInformation and ReflectionEmit permissions.
ReflectionPermission refPerm = new
ReflectionPermission(ReflectionPermissionFlag.TypeInformation |
ReflectionPermissionFlag.ReflectionEmit);
refPerm.Assert();
Any ideas?
Nicole Calinoiu - 27 Oct 2005 13:08 GMT
> I have some simple VB code that subclasses a base class from another
> assembly. The base class exposes an IDataReader via a protected field
[quoted text clipped - 9 lines]
>
> Whenever I call GetField("m_data") it comes back as null.
Might you be able to provide a small sample (à la
http://www.yoda.arachsys.com/csharp/complete.html) that demonstrates the
problem?
> I've also tried calling it with
> BindingFlags.NonPublic|BindingFlags.Instance
[quoted text clipped - 10 lines]
>
> refPerm.Assert();
The only permission required to make that Assert call is
SecurityPermission\Assertion, so any success or failure of that call doesn't
really say much about whether your assemblies have adequate
ReflectionPermission...