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?
4 Answers
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.

- 27,594
- 16
- 81
- 105
-
Could you or anyone else put Pdb2Xml.exe somewhere on the net? I guess it's also usable for unmanaged code, and i dont have a c# compiler. But i only find the sources. Seems to be a great tool. – RED SOFT ADAIR Aug 26 '09 at 10:05
-
You can find the project on github at https://github.com/SymbolSource/Microsoft.Samples.Debugging/tree/master/src/tools/pdb2xml . I also compiled it for your convenience, you can download at https://drive.google.com/file/d/1tymd4aDoBGWKrFhnRJu_pTNSV1J15Ugq/view?usp=sharing (extract with 7Zip). As for usage: all dependencies of the targeted assembly need to be accessible. I simply copied everything into the pdb2xml folder.. – Andreas Reiff May 14 '19 at 15:10
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.

- 554,122
- 78
- 1,158
- 1,373
-
2You don't have to ship the PDB file to *have* the PDB file. As long as you stash it away somewhere when you build, you can refer to it when you get the stack trace. See http://stackoverflow.com/questions/1328836/include-line-numbers-in-stack-trace-without-pdb/1328915#1328915 – tghw Aug 25 '09 at 15:24
-
Yes, that's true. But you have to have the PDB file to get this information - since that's where it's stored by the compiler. – Reed Copsey Aug 25 '09 at 15:27
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.

- 6,175
- 32
- 49
No there is not. All of the information necessary to map lines of IL to the original source file and line number are stored within the PDB. It's not possible to get that information in the stack trace without the PDB.

- 733,204
- 149
- 1,241
- 1,454
-
I'm very certain I can write a much smaller version of IL offset to line numbers than would be present in a PDB file. – Joshua Nov 01 '11 at 19:36