Dan's IK Blog

Periodic ramblings of all things even remotely related to .NET
64-bit (x64) Snoop for WPF Development

The popular Snoop tool from Peter Blois has been out for a long time, and I use it almost every day in my WPF development.  However, there has always been something missing:  a native 64-bit version. 

My coworker Joe and I finally decided that it was worth looking into building one.  There were a few tweaks to the code itself to compile in 64-bit, and then some project build directory settings changes … but for the most part, it was pretty straight forward to make. 

So with permission from Peter Blois, I have created and posted a true 64-bit version of Snoop.  Mind you, this is version 1 of Snoop – haven’t yet tried to tackle version 2.  I tend to use v1 in my everyday WPF dev – not having property editing in v2 is a showstopper for me.

Bit Versions

Snoop works its magic by injecting a DLL into the process space of the app you are snooping.  The problem with snooping a 64-bit app with the original snoop is that the injector DLL was always 32-bit, and when Snoop tries to load a 32-bit DLL into the 64-bit target application, you get the invalid image exception. 

To allow snooping either a native 32 or 64-bit target app, I have built both a 32 and 64-bit version of Snoop and its supporting ManagedInjector DLL.   So unfortunately, the only downside of this approach is that you have to keep both versions around, and use the one that’s right for the bit-level of the target app.  (There has already been a request for ONE version of Snoop that will load the appropriate version of the injector DLL, so maybe someday I’ll dig deeper into that.)

 

Enhancements

While I was in there building Snoop, I decided to throw in a couple other tidbits - either changes to small things that have always bugged me, or small features that I wish the original had. 

  • “ShowAllProperites” ToggleButton is off by default.  I find that more times than not, the properties I want to look at are in the “defaults” set, so this keeps the properties list much shorter.

 

  • Use a 2nd monitor if present.  My everyday use of Snoop is that I choose the app to snoop, the SnoopUI comes up and I move it over to my 2nd monitor.  I added some code to do this automatically if there’s a 2nd monitor present.

 

  • Scroll to Selection – when you snoop on an element in your app with CTRL+SHIFT pressed and the element is found in the tree, the selected item is automatically scrolled into view.

 

  • Custom property filter ComboBoxBlog-Snoop64-1In addition to filtering the properties list by text, there is now a ComboBox next it that allows to filter the properties by functionality.  For example, if you choose “Layout”, you see only properties like Width, Height, Margin, etc. that have to do with layout.  Choose ItemsControl for things like ItemsSource, SelectedItem, etc.   This screenshot shows snooping on a ListBox with the custom property filter set to ItemsControl to quickly see everything related to ItemsControls and Selectors.

 

  • Indexer delve.  This is the small TextBox to the right of the Custom Property ComboBox.  If the current property type (that you’ve delved into) is an ICollection, you can type an index value in the TextBox and delve into that item in the collection.  The indexer delve plays along with all the other delves, so you can pop context to get back to where you came from.

 

Here is the properties window after delving into a collection data type (ListBox.ItemsSource which is ObservableCollection<Person> in this case).

Blog-Snoop64-2

After entering a “1” in the Indexer Delve field (updates on text change), you see the Person object at index 1 in the above list.

Blog-Snoop64-3

 

There you have it.   I hope these enhancements, along with a native 64-bit version are helpful in your WPF development!

Here is the zip with both 32-bit and 64-bit folders.  And since the original source was posted, here is the source code for this updated version.

Published 07-15-2009 3:19 PM by DanHanan

Filed under:

Comments

# Improvements to the WPF Snoop Utility@ Wednesday, September 23, 2009 5:22 PM

I made a couple of improvements to the WPF Snoop utility that I posted a while ago .  (as before

Dan's IK Blog

# re: 64-bit (x64) Snoop for WPF Development@ Wednesday, September 30, 2009 10:43 AM

I'm a huge Snoop fan, but had to stop using once I started with Win7-64. Just tried your build today:

"Cannot explicitly modify Children collection of Panel used as ItemsPanel for ItemsControl. ItemsControl generates child elements for Panel."

Got this after snooping my target app, used Ctrl-Shift to select a section of my UI, moused back over to Snoop main window, and it (snoop) crashed.

Rob Cecil

# re: 64-bit (x64) Snoop for WPF Development@ Wednesday, September 30, 2009 1:46 PM

Haven't seen that error, and I snoop 32 and 64 bit apps on a daily basis.  I cant think of anywhere that Snoop is explicitly modifying the children of a Panel.  Does this happen every time you snoop an app?  A particular app or any app?  If you provide me a few more details (maybe a sample app that makes it crash?), I'm happy to help diagnose it.

DanHanan

# Can't find "entry point" ?@ Monday, November 09, 2009 5:36 AM

(sorry for my english 'cause i'm not)

I can't use Snoop release on my app, i have test many thing but can't get to the point.

System :

Windows 7 x64

Visual Studio 2010 Beta 2 (x86)

Configuration : Release & Debug

WPF 4.0 Application (and C# 4.0)

Snoop (64-bit) : Can't find anuthing running

Snoop (32-bit) :

Found :

VS2010 ("Snoop me" and "Magnify" works)

MyApp : buttons Crash with the message :

Either Application.Current or Application.Current.Mainwindow are not set for this application

I though it come from my OnStartup() override in the App.xaml.cs but with an empty project nothing change.

I've forced the "MainWindow" like :

protected override void OnStartup(StartupEventArgs e) {

base.OnStartup(e);

....

MainWindowV v = new MainWindowV();

Application.Current.MainWindow = v;

...

}

The problem is still there

Alex

# re: 64-bit (x64) Snoop for WPF Development@ Monday, November 09, 2009 6:54 AM

I forgot to mention :

I have export the project to WPF 3.5 Application on VS2008 targeting "AnyCpu" Arch, using Snoop 64bit

and it works ...

As I'm using PFX i can't just stay with 3.5 in order to snoop it

Alex

Leave a Comment

(required) 
(required) 
(optional)
(required)