Debugging Silverlight applications with windbg and sos.dll

Tess Ferrandez

If broken it is, fix it you should

Debugging Silverlight applications with windbg and sos.dll

  • Comments 33

If you have hangs, performance, memory issues, exceptions or crashes in Silverlight applications you can debug them using windbg and sos just like you would if the issues occurred in other .net applications. 

The difference is that Silverlight in IE runs a subset of the framework where the main dll is coreclr.dll rather than mscorwks.dll so you can't use the regular 2.0 version of sos.dll that you can find in the framework directory.  Instead you can install the Silverlight Developer Runtime from and the sos.dll for silverlight will be located in the C:\Program Files\Microsoft Silverlight\2.0.30523.8 directory.

To troubleshoot silverlight applications with windbg and sos you would take a memory dump of the IExplore.exe process that acts as the host for your silverlight application.  You can do so with either adplus (as shown in my lab series) or with debug diag, just remember that the process should be IExplore.exe rather than w3wp.exe.

Debugging Basics

For demo purposes I just created a very simple silverlight app with a button that had the following code really bad code in the onclick method, which will make the application throw an exception that we just swallow, and then "hang" for 25 seconds.



private void MyButton_Click(object sender, RoutedEventArgs e)
        throw new Exception("Test exception");
    MyButton.Content = "Pushed";

To debug the app I follow these steps

1. While it is hanging I take a memory dump of the process using

adplus -p <PID for the IExplore.exe process> -hang

2. I open up the dump in windbg and set the symbol path

.sympath SRV*c:\websymbols*

3. I load up sos.dll from the silverlight directory

.load C:\Program Files (x86)\Microsoft Silverlight\2.0.30523.8\sos

And now I can debug as i would debug any other .net application....

Looking at the stacks to see what is executing

0:010> ~* e !clrstack
OS Thread Id: 0x1460 (5)
ESP       EIP    
02edf858 7d61cca8 [HelperMethodFrame: 02edf858] System.Threading.Thread.SleepInternal(Int32)
02edf8a4 05cdd5f7 System.Threading.Thread.Sleep(Int32)
02edf8b0 05c603b5 TestSLControl.Page.MyButton_Click(System.Object, System.Windows.RoutedEventArgs)
02edf8e8 05cdd425 System.Windows.Controls.Primitives.ButtonBase.OnClick()
02edf900 05cdd328 System.Windows.Controls.Button.OnClick()
02edf910 05cdd2ac System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs)
02edf924 05cdd1e4 System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Object, System.Windows.Input.MouseButtonEventArgs)
02edf934 05c9a3d2 System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32, System.Delegate, System.Object, System.Object)
02edf9bc 05c9838d MS.Internal.JoltHelper.FireEvent(IntPtr, IntPtr, Int32, System.String)
02edfb74 7b7b1720 [GCFrame: 02edfb74]
02edfc30 7b7b1720 [ContextTransitionFrame: 02edfc30]
02edfd28 7b7b1720 [UMThkCallFrame: 02edfd28]


Here we can see the sleep method called from TestSLControl.Page.MyButton_Click...

Looking at recent exceptions


0:010> !dumpheap -type Exception
Address       MT     Size
total 10 objects
      MT    Count    TotalSize Class Name
06307110        1           72 System.Exception
Total 10 objects

0:010> !dumpheap -mt 06307110       
Address       MT     Size
0638d870 06307110       72    
total 1 objects
      MT    Count    TotalSize Class Name
06307110        1           72 System.Exception
Total 1 objects

0:010> !pe 0638d870
Exception object: 0638d870
Exception type: System.Exception
Message: Test exception
InnerException: <none>
StackTrace (generated):
    SP       IP       Function
    02EDF8B0 05C603A0 UNKNOWN!TestSLControl.Page.MyButton_Click(System.Object, System.Windows.RoutedEventArgs)+0x48


StackTraceString: <none>
HResult: 80131500
The current thread is unmanaged

... to name a few examples... In essence, most of what you can look at using regular sos is also available in the silverlight sos.

Have fun,


Leave a Comment
  • Please add 6 and 4 and type the answer here:
  • Post
  • PingBack from

  • My latest in a series of the weekly, or more often, summary of interesting links I come across related to Visual Studio. The Web Developer Tools Team announced the release of the Dynamic Data Wizard Preview 0806 for VS 2008 SP1 . US ISV Developer Evangelism

  • Great post Tess: concise and informative.

    I'd be most interested in any real world Silverlight problems you've solved/investigated 'using the powers of the debugger' in the future.



  • Link Listing - August 21, 2008

  • Post: Approved at: Aug-24-2008 Intersoft demos Silverlight 2 controls

  • Tess just posted an article on how to debug Silverlight application using sos.dll. If you have been using

  • DebugDebuggingSilverlightapplicationswithwindbgandsos.dllWebJavaScriptMemoryLeakDetec...

  • Debug Debugging Silverlight applications with windbg and sos.dll Web JavaScript Memory Leak Detector

  • Back in August I wrote a post about how to debug these types of issues in silverlight applications.&#160;

  • Silverlight 2.0 RTW = Production Debugging Silverlight 2.0 Apps Ok, so we all know that Silverlight 2

  • What if some non-Silverlight component that used mscorwks.dll (a regular .NET component) was loaded into IE? And then a Silverlight app was loaded. Would both mscorwks.dll and coreclr.dll be loaded in the IE process? If so, I guess you could load both versions of sos when looking at a dump (since they have different paths). Is any of this possible?



  • Yes, all of the above is possible...

    In that case you might have to prefix the command with the path !<path>/sos.command  to get the command from the right sos loaded  or alternatively unload one sos and load the other to avoid confusion about where the commands come from...

    if a command is present in multiple loaded extensions, the extension that is last loaded will have presedence  (see .chain for loading order and full name of the extensions)

  • Is this supposed to work by directly attaching to the iexplore.exe process or does it only work by taking a dump? I've some huge memory leaks with my SL2 app (~50 MBs in one transaction) on the client side. I'm trying to investigate the culprit for this.

    Thank you.

  • .NET ASP.NET MVC Beta Source Code Release - Partial Output Caching in ASP.NET MVC - Partial Requests

  • Doug, you can attach live or take a dump, either one will work.

    The reasons for takig a dump would be

    a) to be able to look at it on a different machine

    b) to be able to continue working with the process while you are debugging

    c) to save it if you want to refer back to it

    but there is no difference between what you will see live or in a dump for this purpose...

Page 1 of 3 (33 items) 123