When I’d like to use any technology I’d like to know it first and then use it. How to know all the specifics and details about any technology, 3rd party controls, etc. ? For sure, it’s good to read some introductions how to use it, what the technology, libraries are about but then? reading the blogs, articles, examples … but all of them are very hard to collect and summarize. I think the best technical documentation about any code is the code itself.
I had similar problem with ASP.NET databinding, datasources, etc. I read several books, nice blogs from different people, I used the tool Reflector to look at the source code. But what I missed was to debug the 3rd party code. Why? Because I wanted to run the code and have a look at the code in the runtime. Via Reflector I can look at the code in the design time but via debugger I can check all class and method variables in the runtime. Via debugger I can see the call – stack which is quite hard to explore in Reflector (mainly because of overriding and inheritance).
So let’s recapitulate the problem: debugging the 3rd party libraries (.Net libraries included)
I had a discussion with my colleaugue and he adviced me to use the symbols server from MS. They should be fine at least for MS pdbs but what about other 3rd party libs. But OK. I tried it.
Using the symbol server
Very brief description how to set up the symbol server within Visual Studio .NET 2005 is at: http://geekswithblogs.net/sdorman/archive/2007/05/23/Debugging-in-Visual-Studio-2005-with-a-Symbol-Server.aspx It looked very nice and I was quite lucky that I need just to set it up and I’ll be able to debug 3rd party libs immediatelly without problems.
So I set up the Visual Studio, run the program within debugger. I set the breakpoint too and ….
…..when I looked at the call stack and click to the Stack frame related to the 3rd party code,I get the following screen:
I’m sorry but I’m not assembler friend. Debugging the code via assembler code is for me unacceptable. I was quite disappointed but .. maybe I forgot to set some other property up in order the debugger to display me at least MS IL code.
So the story continues …
I tried to find a developer-friendly way to debug. I think when you don’t have the code but your would like to debug the code anyway then it’s necessary to debug the code via MS IL. So debugging of the 3rd libraries requires MS IL knowledge (I think if you woud like to be a good .Net specialist, you should be familiar with MS IL code, too). Reading MS IL wasn’t any stopper for me so… so I asked myself how to get the MS IL code from any 3rd party library? Of course, via ILDASM tool. As you can think the solution will need a little bit (ildasm/ilasm)-ing. So let’s deep inside it ..
Let me explain the way how to do it on System.Web.dll assembly (because I wanted to explore databinding in ASP.NET v 2.0):
0)copy system.web.dll to “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\PDBs” (PDBs is my custom folder)
1)run Visual Studio Command Tool, go to previously created folder and run “ildasm system.web.dll /out=system.web.il”
2)then run “ilasm system.web.il /debug /dll /output=System.Web.dll”
3)now stop all processes which have loaded the reassembled assembly (hm, good word) system.web.dll: i.e. W3WP,Aspnet_state,VisualStudio2005
4)now run “sn -Vr System.Web.dll” which will skips the string name verification for the specified assembly while installing the assembly into GAC
5)now install the assembly into GAC: “gacutil -i system.web.dll”
6) now clean PDBs folder and keep only PDBs and ILs files. (In our case there will be System.Web.il and System.Web.pdb)
7)now open Visual Studio .NET and set the Tools -> Options -> Debugging -> Symbols to include also the path C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\PDBs
That’s all folks. Now you can set the break-point into i.e. Page_Load event and go to the call stack view and double-click 3rd party frame view and ….
you will get the following screen:
Ok, you can say .. hm, but I’d like to see C# code, too .. at least for looking at the compete method written in C# .. .I offer to you TestDriven.NET. Hm, do you ask what this word has common with debugging? It’s Reflector add-in into VS.NET 2005. So download it and install it and ..
… then you are able to jump directly to the C# code from the debugger.
I hope this will help you to become better specialist and especially to know much better the 3rd party code which is sometimes very important …
I hope you enjoy it and send me any feedback, comments and new ideas how to debug 3rd party libs better and easily.