C # Debug a dynamic-link library with source code when you meet there is no source code available for the current location prompt solution

Source: Internet
Author: User
Tags dedicated server

C # Debug a dynamic-link library with source code when you meet the There is no source code available for the current location prompt solution:

1. First try the most conventional method: clean and then rebuild solution, but not resolved

2. Enter Tools>options, select debugging>general but drop Enable address-level debugging option, remove Require source files to exactly MATC H the original version.

Okay, solve the problem.

Recently in the maintenance of a project, there is a problem, project solution a reference to the third-party DLL files, and I now need to use some of the DLL class library tool classes, but there is no relevant documentation, so I need to debug into the DLL to debug the logic of viewing the code. At first I wanted to reflect the source code through. NET Reflector, but because some of the original methods didn't work. Now I found the source of the legacy DLL, but in another solution B, so now I want to debug the source code, to do is to map the source code into our project DLL. Before introducing the method, we will briefly say a few concepts. PDB files, DLL files, source code CS files. When we want to debug a DLL file, these three are not a few.

DLL file

Is the file to be used when the program executes. Note that the program is running using a DLL as a binary file, instead of the code we write ourselves, the code we write is compiled from the DLL file.

CS Source Code

This is the code that was written to generate the DLL file. When the program is running, it does not need CS file at all.

PDB file

When you compile a project, in the Bin directory, along with the DLL file, you will see a PDB file, what is the file to do? The PDB is the abbreviation for program database, and it becomes the information stored in the symbol file.pdb to map the source code in the. cs file to the corresponding relationship of the compiled DLL file. Debugger, the debugger, uses this information to parse two aspects of information: the line number in the rendered source code in Visual Studio and the address of this line in the DLL, that is, when a breakpoint is set on a line in the source code in Visual Studio, Since debugging is a DLL file, debugger needs to know where the break is in the DLL, while the PDB is recording the correspondence between the line number and the address. Another information that is parsed in the PDB is where the source code for this DLL is. Of course, if you write your own code, the source code is under project. But if we refer to a third-party framework, such as the ASP. NET Framework, we don't have source code locally at this time, and the code address on the remote server is logged in the PDB. In a nutshell, the PDB file acts as a bridge between the DLL and the CS source code.

Now that we have a requirement, for example, I want to debug the process request method of the ASP. NET MVC framework in my MVC project, now that we have no source code, we have no way to set breakpoints, Even if you use the F11 step by step to debug, to this no source code line, also will skip directly, because there is no place to go ah. There is a concept of my Code when debugging, only the DLL of my code can be debugged. In fact, frankly, My code DLL is the DLL with the PDB. To debug the MVC DLL, we need to get the PDB file for SYSTEM.WEB.MVC first. In the debug state of Project, click Debug-->windows-->module, and you will find that the SYSTEM.WEB.MVC DLL is cannot find or open the PDB file state. Microsoft has a dedicated server to provide the framework code, so we can get the PDB file from the server. Then right-clicking the System.web.mvc row in the module and checking the load PDB from server will find that the PDB will load from server to local. If you are debugging MVC code at this point, you will have the same hint.

Because at this time debugger think you have PDB file, is my code, try to debug, but there is no source code, so you will be prompted to map the source code. We now need to set tools-->options-->debugging-->genral-->enable Source server as checked, so that When debugging SYSTEM.WEB.MVC, the source code is automatically downloaded from the server to local. At this point, you can debug classes in the ASP. NET MVC framework such as Mvchandler.

Back to our initial requirements, we are now in the situation where our third-party DLLs do not have a server that can download PDB files. So, we're going to put the DLL in source code solution B in the build, the PDB file is copied to soution a, and in debug mode, the address of the corresponding PDB for the third-party DLL is specified in Moudule. At this time, in debugging, debugger found that the DLL does not have the tag source server address, will be mentioned above, will be prompted to ask you where the source code, this time you map the path to your local source code can be.


Note: In the first case, when obtaining the PDB file for SYSTEM.WEB.MVC, Visual Studio sends a request for a PDB file to Microsoft's specific server, based on the information in the DLL, and downloads the local. The process is very precise, and the downloaded versions are consistent because the DLLs have information records. In the second case, there is no sever available for download and requires human import. This process needs to be very accurate, that is, you solution the DLL referenced in a, must be exactly the same as the PDB you import, exactly, must be generated at the same time as the DLL generation Pdb.vs compiler has such a mechanism, in compiling C # code and generate PDB, There will be an algorithm to optimize the PDB, as if also related to the time stamp, that is, even if the code has no change in the exact same, the PDB generated in two times is not the same, if the debugging when the import inconsistency, is not mapped successfully.

Citation Links:

There is no source code available for the current location solution

Introduce the source code of the third-party DLL into the project

C # Debug a dynamic-link library with source code when you meet there is no source code available for the current location prompt solution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.