Getting method parameters values at runtime

  • Thread starter Thread starter Tom Jastrzebski
  • Start date Start date
T

Tom Jastrzebski

Hello,

Is it possible to get access to method parameters values at runtime, without
referencing them directly?
I am working on a universal error logging for my application. I can easily
obtain class and method names using the StackFrame object but it also would
be nice to know parameters values of the method where an exception occurred.

There must be a way to do this. Visual Studio "Call Stack" window displays
this information.

Tomasz
 
Tom Jastrzebski said:
Is it possible to get access to method parameters values at runtime, without
referencing them directly?
I am working on a universal error logging for my application. I can easily
obtain class and method names using the StackFrame object but it also would
be nice to know parameters values of the method where an exception occurred.

No, there's no way of getting at the parameter values with reflection
etc.
There must be a way to do this. Visual Studio "Call Stack" window displays
this information.

Yes, but that's hooked into the debugger. If you looked at the
debugging APIs you might be able to get the information from that - but
I expect you don't really want to run under the debugger in
production...
 
Thanks for the answer.

Could you give me some hint on those debugging APIs? Where do I look?
I may want to try this approach but only in global error handler. When the
app is about to crush anyway I no longer care about the performance.

Tomasz
 
Tomasz Jastrzebski said:
Thanks for the answer.

Could you give me some hint on those debugging APIs? Where do I look?
I may want to try this approach but only in global error handler. When the
app is about to crush anyway I no longer care about the performance.

Well, I suspect you'll find it's not nearly as simple as that - and
that if the debugger isn't attached when the method starts, it may well
not be able to get the parameters of the method while it's running.

To be honest, I don't know anything about the debugging APIs - I'd have
to do the same kind of Google searches you'd have to. Still, a Google
search for "debugging API .NET" gets lots of likely-looking hits...
 
Back
Top