Saturday 13 March 2010

First steps in debugging silverlight applications with Windbg and sos.dll

I’m really  a beginner in debugging silverlight applications with Windbg. So I am writing this post to tell the world my first steps. This could be useful to other people who are facing the same problems i just have had.

I’ going to link a very  useful blog article from Davy Brion  that i met.

The first is this: http://davybrion.com/blog/2009/08/finding-memory-leaks-in-silverlight-with-windbg/

which explains the basics.

When you insert the command: 

.load C:\\Program Files\\Microsoft Silverlight\\3.0.50106.0\\sos.dll

first check the version number of the framework (‘3.0.50106.0‘ in the example) that could be different on your pc.

After reading the article above i faced two problems.

The first is that since Windbg is a debugger, you can’t attach it to your running silverlight application if another debugger is already attached too.

So remember that you can’t start your application with Start Debugging (F5) but, if you want to start the application with Visual Studio select Start without Debugging (Ctrl+F5) .

The second problem was when i met the following error when i had tried the first command of the article !dumpheap -stat -type MyNamespace  :

Failed to find runtime DLL (mscorwks.dll),

Here you must select the right internet explorer process, the one who is hosting your application. To do this i use Process Explorer’ –> http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

This evolution of Task Manager shows the Internet Explore process that you should use as a child of, i suppose, the process of the whole browser.

Process Explorer

You read the Pid and then you attach WinDbg at the right process by doing File –> Attach To A Process.

With these 2 tips you should follow the linked article without problems!