You can read the information from the .pdb file and evaluate it yourself. It contains all the necessary data. I have not finished reading the code, but I understand the following:
- You get a metadata token from the method in question through reflection
- You are requesting pdb data for this token
- The pdb entry contains the source file name and line number
The metadata current is a 32-bit number consisting of a type byte and a serial number. This token describes each object in the .NET assembly file: types, reference types, methods, fields, etc. This number costs more than the full namespace, type, method name and method signature, and is easier to process. But keep in mind that it is generated by the compiler and may be different in each assembly, so you always need a .pdb file from the same assembly.
The pdb file contains entries about which IL is biased in which method comes from the source. If you do not have a StackFrame, but only have a method, you will probably find several records about the method so that you can use the one with the least offset or describe the entire range in the source code that defines the method.
Here are some links for further reading, the search term is "pdb2xml", which is a sample of old Microsoft code:
Since the .NET API for reading .pdb files requires the availability of build files, this conversion must be done immediately after the build in order to keep the generated XML file really portable.
I actually create this method in my .NET logging solution, FieldLog , to allow source location resolution from crash logs from release builds and de-obfuscate stack traces from obfuscated assemblies.
ygoe
source share