Possible to use Reflector at run time?

Explore, browse and analyze .NET assemblies

Moderators: Luke Jefferson, Charles Brown, StephenC, Alex.Davies, Greg.Tillman, melvyn.harbour

Possible to use Reflector at run time?

Postby jeffkretz » Fri Mar 18, 2011 2:08 am

If this were possible, it would be a tremendous boon to my team's development.

While our software is in beta, any unhandled exceptions are recorded and logged. I use the stack trace, session/form/cookie data (it's a web application) and log everything.

Could I do something like this:

1. Catch the exception.
2. Get the stack trace.
3. Get the stack frames.
4. For each frame, use Reflector to disassemble, at run time, the source code associated with the frame.
5. Use the GetFileLineNumber method of the StackFrame object to highlight the offending line of code.
6. Log the whole thing for review.

Anyone know if such a thing is possible?

Posts: 5
Joined: Thu Apr 02, 2009 6:48 pm

Postby Clive Tong » Tue Mar 22, 2011 10:22 am

It's a good idea and I think the difficulty is in line 5. In order to map from an IL instruction to a line of code you need to have a pdb file. This pdb file is tied directly to the source code.

If you have a pdb file that the original C# compiler generated, then when Reflector generates the source there is no guarantee that it matches the structure of the original C# - for example, there may be extra newlines etc, so the line number may well be wrong.

Generating a pdb and source together is what the Reflector Pro engine does, but this functionality is not exported via the Reflector API.
Clive Tong
Posts: 283
Joined: Thu Dec 04, 2008 5:42 pm

Return to .Net Reflector 6.x and .NET Reflector 6.x Pro

Who is online

Users browsing this forum: No registered users and 0 guests