Problems using Snoop with WPF 4 App

May 19, 2010 at 4:32 AM
Edited May 19, 2010 at 4:54 AM


I have a large mixed mode (native code and WPF) application that, until we moved it to .NET 4.0, was highly Snoopable.  I have downloaded Snoop for WPF 4, both bitnesses.  When I run the 32-bit build of this app and then the 32-bit version of Snoop for WPF 4, my application shows up in the list of WPF applications in the Snoop bar, but when I click the binoculars tool (Snoop This Application), the Snoop window never appears.

This application targets the Client Profile of .NET 4, not the full platform, in case that matters.

Anybody else experiencing this?  It I decide it's worth the time, any suggestions on where to set breakpoints in Snoop code if I want to download the source and debug it?



May 19, 2010 at 2:04 PM

Hmm. Your problem is likely the native code interop scenario ... that has never been fully supported in Snoop. It is a little surprising to me that you say it worked for WPF 3.5 ... but that it doesn't for WPF 4.0.

Could you create a small mixed mode (native code and WPF) test application and send it to me? I'll take a look. My email is my first name followed by my last name at

May 19, 2010 at 2:24 PM

Thanks very much for the offer.  I thought we might get lucky.  I had created a very simple WPF 4.0 app sort of like our large application in that it starts up in native code and then starts creating WPF windows, as a repro for MSFT for a bug in mixed-mode call stacks.  I expected Snoop to fail on that as well, but it didn't.  Since now I have a case that works and a case that doesn't, though, it would probably take less time for me to download the Snoop source and try to debug it here rather than try to figure out what feature of our main application is what triggers Snoop to fail.  I'm going to attempt to reserve tomorrow to do that.



May 19, 2010 at 2:30 PM

Cool. Let me know what you find out.

May 19, 2010 at 8:28 PM

Well, I got a little time today, and I figured out the problem.  Snoop assumes that Application.Current.MainWindow is a legit window that it can set as the owner of its UI.  However, if your WPF app creates other collapsed windows before creating the application's real main window, Application.Current.MainWindow will be the first window that you created, no matter what state it is in.  If it is Collapsed, Snoop throws an exception when it sets the Owner of SnoopUI to that collapsed window, and Show never gets called.

The fix I have made (and can pass along) is to check the Visibility of Application.Current.MainWindow, and if it is not Visible, walk the Application.Current.Windows list until finding a window that *is* visible, and set *that* as the owner of SnoopUI.  If no Visible window is found, put up a message box.  There could be some debate whether Hidden windows should be allowed to own the SnoopUI.  But who would run Snoop on an app that has all of its windows hidden?  So I doubt it.

Nice thing is, this had nothing to do with this being a mixed-mode application.  It's not at all clear why this wouldn't have tripped up Snoop in .NET 3.5, but now that it works, I don't care enough to go figure that out.

It was definitely fun figuring out how to debug both sides of Snoop.



May 19, 2010 at 8:38 PM

Please do pass along the fix and I will look at incorporating it into the code base. Even better if you pass along the test harness demonstrating the problem too ... so I can verify I'm not munging something up as I integrate it.

May 25, 2010 at 4:37 PM

This has been integrated and fixed:

It will be in version 2.5.2.