tags:

views:

81

answers:

2

Hi all,

I'm really stumped by this one!

The StackFrame object (MSDN Link) has a GetFileName method that returns the original path of the source file that compiled the executing method (provided symbols were generated and included with the executing assemblies). It looks like this information is used to generate full exception text.

I'm trying to find a way to get at this information if the method isn't currently executing. I've been poking around the reflection API and haven't seen a way to get at this information. I assume it must be in there somewhere.

Does anyone else know of a reflection based method (or indeed any other method) that can get me the code file name?

Any ideas, comments or abuse gratefully accepted.

Many thanks!

A: 

Use RedGate Reflector decompiler to inspect the assembly containing the class.

munissor
Thanks for your response. I didn't know Reflector could do that - that's awesome, but this is something I'd like to be able to do from code as it will fit into an existing system.
Chip Phat
+3  A: 

Reflection can only provide type information from the assembly metadata. Getting the address requires the .pdb debugging file and the address of the function in memory, as compiled by the JIT compiler. You can't get the address without the StackFrame.GetNativeOffset() method or the debugger interfaces, assuming the method is even compiled. The latter approach can't work in-process, a program cannot debug itself.

The CLR doesn't have any trouble because it can retrieve the method address from the stack frames when it processes the exception. That's still an imperfect art, it cannot see addresses of methods that were inlined. Having those stack frames is the required first step.

Hans Passant
Thanks very much indeed - that makes sense. Ah well :)
Chip Phat