Get line number from exception stack trace

O

Oleg.Ogurok

Hi there,

The .pdb files are generally not installed in a production environment.
As a result, when an exception occurs, the runtime can't resolve the
lines of the code where the problem happened. Instead, one gets the
offsets, e.g.:

[NullReferenceException: Object reference not set to an instance of an
object.]
MyClass.DoSomething(String s) +554

If I haven't changed the source code on my development machine, is
there any way to translate the offset (+554) into the line number?

I tried using ILDASM and looking at the IL but couldn't find anything
that would correspond to offset +554. ILDASM showed the method has
offsets from IL_0000 to IL_00bc

Thanks,

-Oleg.
 
B

Barry Kelly

The .pdb files are generally not installed in a production environment.

This is safe to do, by the way. You can build PDBs for your release
build, and you'll get line number information. Mind that generating the
string which includes the stack trace will be more expensive, though,
because the pdb will be opened up and searched.
I tried using ILDASM and looking at the IL but couldn't find anything
that would correspond to offset +554. ILDASM showed the method has
offsets from IL_0000 to IL_00bc

The offset will probably be in the machine code generated from the MSIL.
You could try debugging the release build in Mixed mode (with "Unmanaged
debugging" turned on) and putting a breakpoint inside the method. By
switching to the CPU view you'll be able to see what happened at that
offset, after you convert it to hex.

-- Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top