❔ Read a .pdb file in C#

Does anyone have a simple example of opening and reading a Windows PDB (not Portable PDB) file in C#? The examples I can find from Microsoft and others are all in C++, and the couple of examples I can find are very old and no longer work.
14 Replies
dreamdoctor
dreamdoctorOP2y ago
Everything I can find says to use Microsoft.DiaSymReader.Native (https://www.nuget.org/packages/Microsoft.DiaSymReader.Native/), however I cannot find a single piece of documentation or further information anywhere.
Denis
Denis2y ago
I believe it is best to use a library for that. dnlib is a wonderful reflection library that has pdb reading features However, I found that reading pdb files can be quite tricky and unstable. I required reading them to determine the source code file for a given type discovered via reflection. Finding the source file worked for some pdbs, while not for others and still to this day I'm not sure what affects this
Denis
Denis2y ago
GitHub
ModularDoc/Resolver.cs at b41eb3adadbd5a4d40ac2a277a3b60c6e2cf7a91 ...
Modular documentation generator for .NET libraries. Currently supporting Markdown only for GitHub, GitLab, and Bitbucket - ModularDoc/Resolver.cs at b41eb3adadbd5a4d40ac2a277a3b60c6e2cf7a91 · hails...
Denis
Denis2y ago
There's also sharpdb or something like that for loading pdbs
dreamdoctor
dreamdoctorOP2y ago
Thank you so much for the information. Were you reading Windows PDBs? From your code it looks like you were working with Portable PDBs?
Denis
Denis2y ago
Should work with both imo SharpPdb is supposed to support switching between the two pdb types Been butchering the name of the library this whole time
Denis
Denis2y ago
GitHub
GitHub - southpolenator/SharpPdb: Library for reading PDB files, bo...
Library for reading PDB files, both Windows and PortablePDBs. - GitHub - southpolenator/SharpPdb: Library for reading PDB files, both Windows and PortablePDBs.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
dreamdoctor
dreamdoctorOP2y ago
Unfortunately, as with every other library I've tried, I can't find a single example to demonstrate how to read native Windows PDB files using the SharpPdb library. I even tried asking ChatGPT, however the code it gave me was basically nonsense.
Anton
Anton2y ago
GitHub
SharpPdb/PdbFileTests.cs at master · southpolenator/SharpPdb
Library for reading PDB files, both Windows and PortablePDBs. - SharpPdb/PdbFileTests.cs at master · southpolenator/SharpPdb
dreamdoctor
dreamdoctorOP2y ago
Thanks but that doesn't help.
Denis
Denis2y ago
How come? It should at least give you some pointers on how to do it. Unfortunately, PDB is quite an undocumented topic, and it will probably require a lot of trial and error
dreamdoctor
dreamdoctorOP2y ago
I've spent three days trying to work it all out. Those tests don't offer any real examples.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server