Decompiling and debugging .Net dll files

Hi All, when you are working with some third party tools there are some times those third party throws errors. As example when you are developing ASP.Net Web Applications with CMS (Content Management System) like SItecore, it throws errors. In these situations we have to check where the error is getting throwing. But the problem is most of the third party tools have assembly (.dll) files which we cannot decompile.

Why we cannot debug them ?
Because, it is a end product and they don't include the .pdb files that need to debug their libraries.

What is a .pdb file ?
A program database (PDB) file holds debugging and project state information that allows incremental linking of a debug configuration of your program. A PDB file is created when you build with /debug (Visual Basic/C#). You can build Visual Basic and Visual C# applications with /debug:full or /debug:pdbonly. Building with /debug:full generates debuggable code. 
- msdn.microsoft.com

Read more about PDB files from here.

So how can I debug their libraries without pdb files ???
Answer: Just create the pdb files !

Creating pdb file and debug library files

1. Download and install 'JetBrains dotPeack'.
To do this we need 'JetBrains dotPeack'. This is free .Net decompiler and assembly browser.
Get JetBrains dotPeack from here and install it on your computer which you have your ASP.Net web solution.

2. Open the JetBrains dotPeack and add the assembly files to it from your solution.



3. Brows for your file and open it.
For this post I'm using a Sitecore 8.0 assembly.

When you add it to the dotPeack it will decompile the assembly. And you can brows through the namespaces and methods.
You might experience some difference with the constrictors. This is because of the dotPeack. It will not decompile exactly as it is.

We are not finish yet. We need to debug code. If you just need to go through the assembly you can stop the process from here. But if you need to debug by attaching break points in Visual Studio you have to go through the following steps as well.

4. Start Symbol Server
In dotPeack we have to start the Symbol Server. Start it from the toolbar.


6. Visual Studio settings
Open your Visual Studio with your project. Go to Tools --> Options
Under Debugging got to Symbols sections. Add new Symbol file (.pdb) location.

NOTE: Give the same location to both Symbol file (.pdb) locations and cache symbols in this directory.


Under the 'Debugging' section, go to General sub section and uncheck 'Enable Just My Code'.

Click OK.

5. Creating the pdb file
Go to dotPeack, Right click on your assembly and click on 'Generate Pdb'.



6. Select the Namespaces that you need to debug. Or you can select the entire assembly.



Then click 'Generate'.

dotPeak will let you know when the pdb file gets generated.



7. Go to the pdb file generated location. Pdb file might generated inside folders.
If it is inside folder make sure you move them to the location that you have defined in the Visual Studio as 'Symbol file (.pdb) locations:'

8. Add dll file to Visual Studio using references.
NOTE: Make sure the location of the dll file that is added to the Visual Studio is similar to the dll file which we added to dotPeack to create the .pdb file. 

9. Brows assembly
In Visial Studio select the assembly from Solution Explorer.
Right click on it and select 'View in Object Browser'


From the 'Object Browser' select the namespace needed. Right click and select 'Go to Declaration'.


10. Debug the assembly
Put a breakpoint to the code part you want to test and test.
If you are triggering the correct place the breakpoint will execute.


Happy debugging... :)










Comments

Popular posts from this blog

Deploy Angular 8 app to Azure with Azure DevOps

Apache ActiveMQ 5 with .Net Core 3.1 and C#

Firebase with.Net Core and C#