Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Security / October 2005

Tip: Looking for answers? Try searching our database.

Accessing a Protected member of a base class with Reflection.Emit

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gary@designercontrols.com - 24 Oct 2005 13:41 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
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...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.