How can I include line numbers in a stack trace without a pdb?

17,245

Solution 1

You can't get a stack trace with line numbers directly from your application unless you bundle the PDB. However, if you have the PDB files for the same version of the app that you ship to your customers, and you don't mind some light scripting, then you can turn the .NET stack trace and IL offsets back into line numbers.

During your build process, use Mike Stall's pdb2xml converter, distributed as part of his excellent MDbg managed code debugger, and store them some place secure (e.g., source control). When you get a stack trace back from the client, you can query the IL offset from the XML data to determine the relevant line number. If your stack traces get submitted to a website, you can even automate the conversion, so that developers will already be getting fully detailed stack traces by the time the cases hit their inbox.

Solution 2

No. The line numbers are part of the debugging information, which is only stored in the PDB file. That is the reason PDB files exist in the first place.

Solution 3

Not the appropriate answer to your question but i have a suggestion. You could incorporate a logging mechanism and get these log files alongside the stack traces. If you include line numbers in your log messages, you can combine the logging information with your stack trace manually.

If you don't want to take up much space you can use limited size log files, this way only the most recent log messages will be kept.

We use log4net library for our logging needs, I recommend you take a look.

Share:
17,245
user1601201
Author by

user1601201

Updated on June 04, 2022

Comments

  • user1601201
    user1601201 almost 2 years

    We are currently distributing a WinForms app without .pdb files to conserve space on client machines and download bandwidth. When we get stack traces, we are getting method names but not line numbers. Is there any way to get the line numbers without resorting to distributing the .pdb files?