Accessing protected properties at runtime

  • Thread starter Thread starter Joe Ross
  • Start date Start date
J

Joe Ross

We are wrestling with an intermittent database error and would like to be
able to capture some specific data when the error occurs. We are trying to
grab as much state information from a SqlDataReader object as possible.
Unfortunately (for our cause here), the data reader is sealed and most of
the meaningful properties are either protected or private. However, we can
access these items when using QuickWatch inside the debugger (we have been
unable to reproduce the problem in-house, so this does us no good).

Is it possible to grab things like _command, _activeConnection, etc at run
time? Will reflection give us this flexibility? Is there any other way to
get more complete state information on a SqlDataReader?

Thank you for any suggestions...apologies in advance for the cross-posting,
-joe
 
Hi Joe,

Reflection is the way to go.
Your application has to be fully trusted (I think).
See Type.GetProperty or Type.GetField methods.
 
Thanks! I'm making some progress using GetFields (with BindingFlags) and
then the GetValue method of the FieldInfo.

This looks like it will get me what I need.

Thanks
-joe

Miha Markic said:
Hi Joe,

Reflection is the way to go.
Your application has to be fully trusted (I think).
See Type.GetProperty or Type.GetField methods.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Joe Ross said:
We are wrestling with an intermittent database error and would like to be
able to capture some specific data when the error occurs. We are trying to
grab as much state information from a SqlDataReader object as possible.
Unfortunately (for our cause here), the data reader is sealed and most of
the meaningful properties are either protected or private. However, we can
access these items when using QuickWatch inside the debugger (we have been
unable to reproduce the problem in-house, so this does us no good).

Is it possible to grab things like _command, _activeConnection, etc at run
time? Will reflection give us this flexibility? Is there any other way to
get more complete state information on a SqlDataReader?

Thank you for any suggestions...apologies in advance for the cross-posting,
-joe
 
Hi Joe,

Yes, probably. Take note that since they are not public properties their
behaviour *might* change in different framework versions.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Joe Ross said:
Thanks! I'm making some progress using GetFields (with BindingFlags) and
then the GetValue method of the FieldInfo.

This looks like it will get me what I need.

Thanks
-joe

Miha Markic said:
Hi Joe,

Reflection is the way to go.
Your application has to be fully trusted (I think).
See Type.GetProperty or Type.GetField methods.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Joe Ross said:
We are wrestling with an intermittent database error and would like to be
able to capture some specific data when the error occurs. We are
trying
to
grab as much state information from a SqlDataReader object as possible.
Unfortunately (for our cause here), the data reader is sealed and most of
the meaningful properties are either protected or private. However,
we
can
access these items when using QuickWatch inside the debugger (we have been
unable to reproduce the problem in-house, so this does us no good).

Is it possible to grab things like _command, _activeConnection, etc at run
time? Will reflection give us this flexibility? Is there any other
way
to
get more complete state information on a SqlDataReader?

Thank you for any suggestions...apologies in advance for the cross-posting,
-joe
 
Back
Top