how to detect parameter values passed to method  
Author Message
TalhaAziz





PostPosted: .NET Base Class Library, how to detect parameter values passed to method Top

i want to log the method's name and the list of parameters along with there values. Retrieving the name and names, position of parameters is easy, but can someone help me out in finding values to these parameters

whenever an exception occurs, i do the following


Dim paramInfo() As System.Reflection.ParameterInfo = ex.TargetSite.GetParameters()
Dim i As Integer = 0
For i = 0 To paramInfo.Length - 1
Response.Write("Parameter " & i + 1 & " Name : " & paramInfo(i).Name & "<br><br>")
Response.Write("Parameter " & i + 1 & "Type : " & paramInfo(i).ParameterType.ToString & "<br><br>")
Next



.NET Development26  
 
 
Brendan Grant





PostPosted: .NET Base Class Library, how to detect parameter values passed to method Top

In general reflection is used to learn about a type without having to create an instance of or have a reference to one and once the desired information is gathered, it is possible to act on it should you have a reference to an instance... without this reference though there is no direct way to get the values.

The same goes for this case... the data you are using from TargetSite is the reflected data about the method where the exception came from including information about the parameter types... but not the values as references passed into the method no longer exist.

One option to get the values that were passed into the offending method would be to catch the exception there and either log the values or wrap them into a new exception whose InnerException property refers to what you just caught... and throw the whole thing back up the call stack to your normal logging code.

Would this work for you



 
 
Mattias Sjogren





PostPosted: .NET Base Class Library, how to detect parameter values passed to method Top

You can't do that, at least not with Reflection.



 
 
Kojak1969





PostPosted: .NET Base Class Library, how to detect parameter values passed to method Top

Hi Kamii47,

I am trying to do accomplish the same task ( getting the parameter value). Did you find a solution to this problem


 
 
TalhaAziz





PostPosted: .NET Base Class Library, how to detect parameter values passed to method Top

you mean there is no way to do it


 
 
Mattias Sjogren





PostPosted: .NET Base Class Library, how to detect parameter values passed to method Top

You can get to parameter values with the native debugging and profiling APIs, but I don't think that's going to help you here.



 
 
TalhaAziz





PostPosted: .NET Base Class Library, how to detect parameter values passed to method Top

and where can i find tht
i wud b thankful


 
 
TalhaAziz





PostPosted: .NET Base Class Library, how to detect parameter values passed to method Top

hey .. i came accross this Profiling API ... its says under the "Describing and Decoding Function Arguments" heading :

"Now that you have callbacks for the function at the point it is being entered and exited, you can examine arguments and return values."

i havnt tried it yet but i guess this will solve the problem