❔ 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
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.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 thishttps://github.com/hailstorm75/ModularDoc/blob/b41eb3adadbd5a4d40ac2a277a3b60c6e2cf7a91/src/Components/Members/MarkDoc.Members.Dnlib/Resolver.cs#L302
Here is my attempt at loading pdbs
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...
There's also sharpdb or something like that for loading pdbs
Thank you so much for the information. Were you reading Windows PDBs? From your code it looks like you were working with Portable PDBs?
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
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.
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.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.
GitHub
SharpPdb/PdbFileTests.cs at master · southpolenator/SharpPdb
Library for reading PDB files, both Windows and PortablePDBs. - SharpPdb/PdbFileTests.cs at master · southpolenator/SharpPdb
Thanks but that doesn't help.
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
I've spent three days trying to work it all out. Those tests don't offer any real examples.
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.