Debug any third party library(.Net DLL) without source code

Debug/Step into any .Net DLL (including third party libraries) to see its internals with ease using JetBrains dotPeek – a Free .Net Decompiler

 

Introduction

Have ever imagined about stepping into(F11) the third party libraries to check out how that works? That is absolutely possible. Continue reading!!

Pre-requisite

JetBrains dotPeek – a free .Net decompiler. Just download and install it.

Steps

I will walkthrough with steps to debug/step into a method JsonConvert.SerializeOject() in the famous third part library – Newtonsoft.Json from a console application.

1. Create a console application in VS and then install ‘Newtonsoft.Json’ library either from Nuget or from local system if already exists.

2. Copy paste below code in the Console app. Refer ‘Newtonsoft.Json’ library at using section.

    public class Employee
    {
        public string Name { get; set; }
        public int Id { get; set; }
        public string Location { get; set; }
    }
    class Program
    {
        private static void Main(string[] args)
        {
            var emp =new Employee() { Id = 1,Location = "Blr",Name = "Kani"};
            var serialized = JsonConvert.SerializeObject(emp);
            Console.ReadLine();
        }
    }

2. Now open dotPeek. Click on File->Open to locate the library ‘Newtonsoft.Json’ and open it. If installed through Nuget, then it can be found uder packages folder in your console app solution folder.

3. Once loaded in the Assembly explorer, right click the library and click on ‘Generate Pdb’.

3. Specify a folder to save the PDB file generated for the library. PDB file contains the symbols for the dll which is used by VS Debugger to debug code in the dll. In this case, select only Newtonsoft.Json as we are not stepping into its dependent assemblies.

4. All set now. Lets set a breakpoint on line JsonConvert.SerializeOject() and press F5. Pressing F11 at the breakpoint hit wont do anything at this point of time. Stop the debugger. We need to do one final critical step.

5. Copy the pdb file saved earlier from the folder mentioned in dotPeek and paste it over under bin/debug folder in your project solution folder.

6. Now, You should be able to step into the method.

Happy debugging!! Play around it and do share your thoughts.

One thought on “Debug any third party library(.Net DLL) without source code

Leave a comment