Update 18th january 2011: as Cory pointed out, the latest version of Snoop is now available on CodePlex.
If like me you’re curious about how big WPF applications are made, you probably tried to use Snoop to inspect the visual tree of Visual Studio 2010 Beta2. And you probably had a problem because Snoop wasn’t able to detect the devenv process of VS2010:
I wasn’t sure about the cause of this problem, but I grab the source of Snoop and took a look at the code that list the available window:
public void Refresh() {
this.windows.Clear();
foreach (IntPtr windowHandle in NativeMethods.ToplevelWindows) {
WindowInfo window = new WindowInfo(windowHandle, this);
if (window.IsValidProcess && !this.HasProcess(window.OwningProcess))
this.windows.Add(window);
}
if (this.windows.Count > 0)
this.windowsView.MoveCurrentTo(this.windows[0]);
}
I setup a breakpoint to find out what was wrong and discover that the window.IsValidProcess failed with the VS2010 process. Because I just wanted to check if it was the only reason why Snoop wasn’t able to inspect it, I hack the code to remove this test:
public void Refresh() {
this.windows.Clear();
foreach (IntPtr windowHandle in NativeMethods.ToplevelWindows) {
WindowInfo window = new WindowInfo(windowHandle, this);
if (/*window.IsValidProcess &&*/ !this.HasProcess(window.OwningProcess))
this.windows.Add(window);
}
if (this.windows.Count > 0)
this.windowsView.MoveCurrentTo(this.windows[0]);
}
And it’s working:
Happy exploration with Snoop 🙂
Out of curiosity, did you rebuild Snoop using VS2008 or VS2010? And if you used VS2010, did you build against .NET 4.0?
I used VS2008 to rebuild Snoop. Are you thinking about anything particular by building it against .Net 4.0 ?
I was thinking that because several of the components in VS2010 itself were built with WPF 4.0, Snoop might have to be built against 4.0 as well.
If you go one level deeper, you’ll see that IsValidProcess explicitly returns false for devenv, with a comment of “Remove VS, since it loads the WPF assemblies but we know that it doesn’t work”. Presumably this is referring to VS2008. So you should be able to just remove that condition and still filter out stuff that won’t work.
Just ran across this post … and thought to point people to http://snoopwpf.codeplex.com. The latest versions of Snoop support WPF 3.5/4.0 … and x86/x64 … and I also removed that if check for devenv.exe some time ago.
Thank you Cory for the feedback. I updated the post.