When does the MethodHandle of an exception change?
I am trying to check if I can combine the exceptions together with some legacy code. I have a class Logger
that takes in an exception and logs it. Ideally, I want to get the unique ID (regardless of the text) where the exception was thrown.
I stumbled upon Exception.TargetSite.MethodHandle
. It seems to be an integer that I could use to do what I wanted. In debug, I threw an exception several times and noticed that the values ββwere static, big!
So I moved the exception to confirm that it will change, if the exception was different, the value changed and great!
I returned the exception to where it was originally and was checked again, waiting for the original integer value to return, but it didn't, it returned a completely different value. :(
It seems that the values ββchange every time the source is recompiled.
This brings me to my question. The documents MethodHandle
are not large :
Gets a handle to the method's internal metadata representation.
Thanks to Microsoft for very informative. I'm guessing it MethodHandle
is some kind of in-memory address for the method? I'm not sure though. Can anyone explain when and why this value changes? Is this a stamp in the assembly or is it a memory address on the stack or heap? Will it change when the process is recycled?
source to share