Using Snoop to take a look at VS2010 !
.Net, Visual Stutio November 3rd, 2009If 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:
1 2 3 4 5 6 7 8 9 10 11 12 | 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:
1 2 3 4 5 6 7 8 9 10 11 12 | 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



November 3rd, 2009 at 7:25 pm
Out of curiosity, did you rebuild Snoop using VS2008 or VS2010? And if you used VS2010, did you build against .NET 4.0?
November 3rd, 2009 at 8:09 pm
I used VS2008 to rebuild Snoop. Are you thinking about anything particular by building it against .Net 4.0 ?
November 3rd, 2009 at 8:18 pm
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.
November 16th, 2009 at 5:23 am
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.
February 7th, 2010 at 4:20 am
[...] Too bad I can’t use Snoop at first on Visual Studio 2010 running instances to prove this, but you can fix Snoop directly in the code using this tips. [...]