cplotts on the Internet

Ok, I know it has been forever since the last Snoop trick! My apologies! I have a whole list of things that I want to show off … but, man, where do people find the time to do these types of things?!

Often, I have had to choose between working on Snoop … versus documenting what it can do. I have often chosen the former because I think that Snoop is fairly obvious to use … but then I am reminded that I am an expert user of it and that many of its features are really quite hidden. For example, how can you easily select the visuals you want to Snoop on? Why, with the Ctrl-Shift Mouse Over trick, of course. Our first two tricks (Trick 1, Trick 2) covered that particular piece of hidden functionality.

So, in this trick, I want to show off a new piece of functionality that we introduced in version 2.7.0 … what I like to call the crosshairs functionality.

This functionality is all about avoiding the combo box of Snoopable applications. It took forever to iterate over all the applications on the system … seeing if each one was a WPF app or not … and filling up the combo box as we go. Why couldn’t we just select that app that we want to Snoop with the cursor? And that is exactly what we did.

Snoop Tips & Tricks #3: The Crosshairs

Now, it is super fast to Snoop an app! You simply launch the Snoop app chooser, drag the crosshairs on top of the app you want to Snoop … and wham bam … you are Snooping.

That is, it can be used to Snoop transient visuals … or visuals that aren’t currently in the visual tree. A perfect example of this type of visual … are combo box items.

Snoop Tips & Tricks #2: Snooping Transient Visuals

One thing I forgot to mention in the video … check out the root of the visual tree after I have used the Ctrl-Shift Mouse Over trick on the combo box item … it is not an App object … but a PopupRoot object. This is further indication that Snoop has refreshed the visual tree and placed the transient visual there in place of the normal App object.

Problems, Problems

The above blog post title is supposed to be kind of a joke. I keep telling people I’m funny. Snoop supposedly has been supporting WPF 4.0 for some time now. Unfortunately, however, there were times where (1, 2) WPF 4.0 applications weren’t showing up in the App Chooser.

In one situation, PresentationFramework.dll wasn’t showing up in the list of loaded modules for the application being Snooped. So, I simply started searching for any of the following assemblies: PresentationFramework.dll, PresentationCore.dll, or wpfgfx_v0400.dll.

But, that didn’t work in all situations.

For sometimes, PresentationFramework.dll shows up as PresentationFramework.ni.dll which I believe is the Ngen(ed) version of the assembly. At other times, it isn’t wpfgfx_v0400.dll that shows up in the list of modules, but wpfgfx_v0300.dll. The former is the milcore for WPF 4.0 and the latter is the milcore for WPF 3.5.

At this point, I just searched for the roots of all these names, i.e. PresentationFramework, PresentationCore, and wpfgfx.

But, again … that didn’t work in all situations. Humility, is a virtue … humility is a virtue.

For some reason, at times, these modules show up in lower case. Don’t ask me why. If someone can shed light on this, please do. So, I’m now searching for the roots of these assemblies in a case-insensitive way. Granted, I probably should have seen that one coming.

Snoop v2.6.1

Snoop v2.6.1 fixes these issues and others. After yet another fellow experienced this problem and since more people are going WPF 4.0 all the time … I figured it was time for a release.

This release also contains some usability improvements from fellow Snoop aficionado, Dan Hanan. In particular:

You can now delve properties by double clicking on the name.

You can now modify the filter sets to contain what you wish to be filtered.

You can now use the mouse wheel to modify property values.

I also want to say that I have a whole bunch of things lined up for integration into Snoop, but have been struggling to find time. For example, another fellow added the ability to capture some hi-res screen shots from Snoop. So, there is definitely going to be a vNext for Snoop … and hopefully soon.

Snoop Tips & Tricks

For a while now, I’ve been contemplating a blog series on Snoop where I highlight different tips and tricks, and in general, how to use Snoop. And with this release, I’m going to kick it off with the most important one of them all: the Ctrl-Shift Mouse Over trick.

Today I got a question about whether Snoop supports XBAPs. Actually, this is something I’ve been meaning to look into for a while.

So, I took the two necessary seconds to create a test XBAP project and tried Snooping. It didn’t work. When launching Snoop after running the XBAP, you see PresentationHost.exe in the App Chooser (PresentationHost.exe is the process that the browser launches in the case of an XBAP).

However, trying to Snoop it (clicking the binoculars) … results in … nothing, not even an error.

Now, the person asking … pointed out a Josh Smith’s blog post on the matter … where he discusses three tips for working with XBAPs … one of which is that Snoop doesn’t work, but that Mole does. In order to get Mole to work, however, you must (at least temporarily) make your XBAP a full trust application.

Hmm. That got me thinking. Yes, I know that is dangerous.

A lot of my efforts with Snoop to date … have revolved around getting edge case scenarios to work … and I have modified the start up process significantly. So, I thought, I should quickly check to see if Snoop now works … as long as I change the XBAP to a full trust application.

And … woohoo … it works!

So, all you need to do is go to the Project Properties window, navigate to the Security tab, and check ‘This is a full trust application’.

Hope that helps, and yeah, Snoop rules!

p.s.

I did also verify (while writing up this post) that neither Snoop 1.0 (Pete Blois’ original version) nor Snoop 2.0 (Pete Blois’ newer stylized version) worked with XBAPs.

The other day, I ran into a situation (see the attached project and here for more info) where I wanted to debug the .NET Framework in order to see how something was working.

Unfortunately, Visual Studio’s native support (see Scott Guthrie’s blog post or Shawn Burke’s blog post) for doing so was failing me. I was eventually able to get that working for .NET 4.0 but not .NET 3.5 SP1 (see this forum thread), but in the meantime … I had to turn to other methods.

So, what is one to do when this happens? Is all lost? Not at all, for you can use .NET Reflector Pro to do the same thing.

.NET Reflector is a very popular .NET utility created by a Microsoft employee, Lutz Roeder. It allows you to explore and analyze .NET managed assemblies. This utility can also be extended by way of add-ins and there is a whole bunch of them out there.

A while ago, Lutz Roeder, decided to let Red Gate take the reins, and they then went ahead and added the ability to allow a user to debug into third-party code and assemblies by way of a Visual Studio add-in.

And that is what I’m going to show you how to do, step-by-step.

Install .NET Reflector Pro

The first thing that you need to do, obviously, is to download and install .NET Reflector, if you haven’t already. There is a download link here.

It comes down as a zip file, so simply extract the contents to a convenient location. Launch it and then select Tools->Integration Options. Here is the dialog that comes up.

This dialog allows you to easily install the .NET Reflector add-in … into Visual Studio. Choose the versions that you want and click OK.

Tell Visual Studio to Disable Optimizations

The next step is very important. If you forget it, you will be frustrated once you get to actually debugging the source code … because all the variables will be optimized away and Visual Studio will also step through the code in odd ways.

So, go to my earlier blog post and follow its instructions. (Also, don’t forget, if you are debugging a Visual Studio 2010 application, to make sure you update the path to devenv.exe … in the .cmd file you create in this step.)

Choose the Assemblies to Debug

Next, launch Visual Studio with the .cmd file from the previous step and load up the project that you want to debug. Go to the .NET Reflector menu and select ‘Choose Assemblies to Debug…’

If you don’t have your options set correctly, the following dialog will come up. Click ‘Turn off “Enable Just My Code”’ to continue.

Now, choose which assemblies that you wish to debug into … via the following dialog.

In my case, I want to debug the ContentPresenter.EnsureTemplate method and the ContentPresenter class lives in PresentationFramework.dll. How do I know this? Well, through .NET Reflector, of course.

Activate .NET Reflector Pro

Once you click OK to the above dialog, you may get prompted with the following dialog.

This, unfortunately, brings up an annoying issue. Even though Red Gate has kindly provided a 14-day trial to use the Pro features of the tool … your trial starts when you install the software and not when try to use the debugging feature for first time.

That is, for me, I was never able to take advantage of the trial period as I had long had the software installed (it is always one of the first pieces of software I put on a newly paved development machine).

So, if you are in this situation, go buy a license and then Activate it here.

Let .NET Reflector Decompile the Assemblies

5. At this point, .NET Reflector Pro is disassembling the assemblies that you have chosen and also reassembling them so that they can generate .pdb files. This process takes quite a bit of time and so they also stuff the output into the ‘Debug Store’ so that you don’t have to do this every time.

If you’ve been around the .NET world for a bit, you’ll notice the similarities in the above step to what you had to do manually in this CodeProject article. And, if you recall, what you ended up debugging … was IL, not C# or VB.

Eventually, everything will succeed.

Verify Your Tools->Options Debugging Settings

At this point, bring up the Tools->Options dialog and go to the Debugging/General tab. Everything should be fine, but as a point of education … and to verify that everything is okay … make sure that all settings pointed to by the red arrows are set as shown.

.NET Reflector cleared the first one (‘Enable Just My Code’) for you … but make sure it is unchecked.

Also, make sure that ‘Enable .NET Framework source stepping’ and ‘Enable source server support’ are unchecked. These options are checked when you are using Visual Studio’s native support to debug into the .NET Framework (mentioned above) … but we don’t want them checked now … so that there is no cause for confusion.

Finally, the ‘Require source files to exactly match the original version’ is not strictly necessary. However, I believe I have had issues in the past if this was checked. If you leave it checked, just keep it in mind, so if things aren’t working you can then try unchecking it.

Next, check out the Debugging/Symbols tab. Below, you can see where .NET Reflector has installed the .pdb files. Make sure those locations are checked … and make sure that everything else in that list is unchecked … especially ‘Microsoft Symbol Servers’

And, very importantly, make sure you have a clean symbol cache … by clicking the ‘Empty Symbol Cache’ button. Why is this important? Well, it ensures that all the .pdb files will be coming fresh from Reflector … and won’t be a stale .pdb from a previous effort at trying to use the native Visual Studio support.

What is the Symbol Cache? Well, the Symbol Cache is where the .pdbs are copied to … so that you don’t have to keep downloading them from the Microsoft Symbol Servers … obviously an important option when using the native Visual Studio support … but not super important when dealing with .NET Reflector. However, I believe Reflector’s .pdb files still get copied to the Symbol Cache.

Debug the .NET Framework (Call Stack Approach)

Now, you need to figure out how to set a breakpoint so that you can break into the application and debug the .NET Framework. The first mechanism is just to set a breakpoint on a local (non-framework) method that you know will cause the class of interest to be on the stack. Then you can double click the stack frame and set another breakpoint as necessary.

For example, let us say that I want to debug System.Windows.Application.DoStartup. I know that the Application class will probably be on the stack if I put a breakpoint in the InitializeComponent method of my MainWindow. So, that’s exactly where I put it.

One thing to note here is that gray text indicates that a .pdb has not been loaded for that assembly while black text indicates that a .pdb has been loaded. That is, in the above example, only PresentationFramework has an loaded .pdb.

And, look! Application.DoStartup is on the stack. Double click that stack frame to bring you to the code.

At this point, you can debug as normal. You can step, watch variables, and more. In the above screen shot, you can see that I set a new breakpoint at the start of the method to be hit when I restart the debugging session. Restarting the application, shows that I can verify that MainWindow.xaml is my StartupUri.

Debug the .NET Framework (Method Breakpoint Approach)

Unfortunately, the above call stack approach to debugging the .NET Framework will only get you so far. Another method I have used in the past is to simply set a breakpoint on a method name. How to do this is not very obvious, though.

The trick is to set a breakpoint via the New->Break at Function menu item in the Breakpoints debugging window.

The New Breakpoint dialog comes up. Simply, and carefully, type the name of the method, prefixed by its Class name, like so:

It will complain, but just click OK.

At this point, just hit F5 (Debugging->Start Debugging) and do what you need to do to hit the breakpoint. And, wa la, here I’ve hit my breakpoint:

The real question that prompted all of this desire to debug the .NET Framework was to see whether the DataContext was getting set or cleared inside of ContentPresenter. And so, I set the following breakpoints and step to my hearts content.

Summary

Sometimes, you are up against the wall. You are trying to determine if the .NET Framework has a bug in it … or you’re just trying to get a better grasp about what is really going on in that big black box.

And, while debugging the .NET Framework is best done natively inside of Visual Studio (it’s easier and you can see comments in the source code), it doesn’t always seem to work. Sometimes the assembly you are trying to debug is not supported and at other times the symbol servers don’t seem to be up to date with the released bits.

However, .NET Reflector Pro can come to your rescue in these situations. It can also debug any third-party assembly, regardless of whether it’s Microsoft’s or not.

Good hunting … I hope this helps someone out! Leave a comment if it does!

Haven’t I already said that the community has just been awesome in regards to Snoop?

Well, here is another piece of evidence!

The other day, a developer, Bruno Martinez, from Uruguay contacted me and wanted to contribute to Snoop by making it so that there was only 1 version, instead of the 4 currently required at that point.

If you recall …

You needed a version for WPF 3.5 and 32-bit.

You needed a version for WPF 3.5 and 64-bit.

You needed a version for WPF 4.0 and 32-bit.

You needed a version for WPF 4.0 and 64-bit.

Yuck! Of course, it was better than not being able to Snoop in those situations. 🙂

Well, after integrating Bruno’s changes … you just need:

Snoop

Yeah, that’s right. There are no labels! Thank you, Bruno!

I’m obviously tickled by this … since it was a usability nightmare trying to figure out what version you needed to run … but there are host of other fixes/improvements as well. In particular, the Snoop start-up process is much more robust than it used to be and it can handle some fringe cases that it wasn’t able to before.

Ok, I just have to blog about this, because I just figured out an issue that’s been driving me nuts, nuts, nuts.

In some xaml files, I had no folding editor … and no IntelliSense!

What I discovered was that if I delete the local namespace declaration (and then add it back again), the folding editor starts working again.

Then, I discovered that if I just leave out the local namespace declaration … instead of adding it back, IntelliSense starts working again. Annoying … since I have to remember to put the namespace declaration back before checking it in.

So, I decided to do a search and see if anyone (besides me) had run into this problem. Well, as you all know, the trick to searching for anything on the internet is getting the right search string. Well, I got lucky. This search brought me to this blog post.

It wasn’t exactly my problem, but what I found was that if I added an ‘;assembly=’ to my local namespace declaration … everything started working again … and would continue working even if I closed and reopened the file! Woot! 😀

Not only did I have the chance to attend my first PDC recently, but my gracious employer sent me to MIX10 this year. I’ve always wanted to go to this conference as I have design interests and tendencies and this is place where conversations about design happen in conjunction with the Microsoft technology stack.

Here is my personal recap of the event. I did this for PDC09 and it was quite helpful to not only reflect back on the conference but also in compiling a list of sessions that I wanted to watch offline (or rewatch again).

The main excitement was, of course, Windows Phone 7. However, my main objective at the conference was to hit up a lot of the sessions on design, learning more about it myself, and how I can better change my own personal development process as well Starkey’s development process. With that in mind, and especially because he is doing some iPhone development, my colleague picked up the Windows Phone sessions. I’m definitely going to dive in on some of those now that the conference is finished.

The best part of the conference was probably just meeting and hooking up (for the first time) with some of the other WPF Disciples. You can always take in the conference offline (and often in a better manner), but it isn’t every day where you can talk with (and have fun with) great minds and people.

It was an excellent conference! I hope I will soon be able to attend again.

Sessions That I Attended

This workshop and Robby’s other session (which was kind of a follow-up to the workshop) were the highlights of conference for me. He is a designer that has a background in development and was part of the team that made WPF. He has done some beautiful and amazing work. A recent piece of work is his design efforts on Seesmic for Windows (which has been converted from WPF to Silverlight recently). He is also the creator of one of my favorite tools: Kaxaml. Besides the cool name, it is the best loose xaml split-view editor out there. The session was all about introducing design to people who don’t have a background in design. As this was a pre-conference workshop, it probably won’t be released as a video you can watch offline. However, Robby also did this session last year, and for some reason they did release it for MIX09. A must watch.

I was very excited for this session because Arturo is a designer PM for Microsoft. Last year he published a great series on UI Design for Developers. Unfortunately, they changed things around and he was not the one presenting but the content was still top-notch. A set of twins, one a developer (Luigi) and one a designer (Guido), presented for the first two hours. They talked about the design and development process for their company, Archetype. They also showed off some amazing experiences they’ve created and then how to do create those experiences in Expression Blend. One of those applications was a Windows Phone 7 news reader that was jaw-dropping (and demoed in the keynote) and it was obvious that they get and totally understand the designer/developer collaboration/workflow. I encouraged them to blog about this because I think a lot of people could learn from them. Finally, Corrina Black finished off the third hour with a high-level Windows Phone 7 design overview. As before, since this was a workshop, the video will likely not be posted … which is too bad. Definitely worth a watch, if it becomes available.

This keynote was all about Windows Phone 7 where Joe covered what it was about and Scott Guthrie covered the development tools (Visual Studio 2010) and technology (Silverlight, XNA) for the phone. The only disappointment was that they didn’t hand out a phone for us to start playing with. PDC really set the bar high for swag (they gave us a free netbook at that conference). I really, really like that I’m already a Windows Phone 7 developer due to my WPF and Silverlight skills.

This was a session by Andy Hood of AKQA. He leads a creative development team there and ran through four AKQA gigs where they blended (think: no rough edges) technology with great design. My favorite was how they used Photosynth in a Facebook Connect game called 221B (that is associated with the Sherlock Holmes movie). They also went to great lengths to remove the Facebook branding and from what they showed, you couldn’t tell it was associated with Facebook at all. Favorite quote: “Beware the lollipop of mediocrity, lick it once and you will suck forever.”

Here is another session that I was greatly looking forward to and I wasn’t disappointed. Laurent is a fellow WPF Disciple and his session was an Open Call session that was voted in by the people planning on attending MIX. That is something in and of itself. He covered what the pattern is and what the pattern is not with a special emphasis on how to keep things blendable (i.e. how to use MVVM and still be able to use the design surface in Blend). If you know me, you know that is right up my alley! He also went over what is contained in his MVVM Light Toolkit. Laurent in a word, rocks. Definitely a must watch.

I’ve already mentioned (above) that this session along with the workshop were my favorites. This session was more practical, more of the how, and less of the theory of design. In particular, he went through and gave the audience 10 design attack moves. My favorite was number 5 which was: Learn Technique. And, as an example, he showed off several techniques that he uses in Photoshop … a couple of which use blend modes. Ah, now, you see why it was my favorite! I just so happened to have created a blend mode library for WPF & Silverlight (see here and here). I really liked number 4 too which was: Sketch Early and Often. I don’t even have to say this: definitely a must watch.

This keynote was focused on Internet Explorer 9, design, and OData (a web protocol for querying and updating data on the web). Dean Hachamovitch talked about what’s new in IE9 and I was particularly impressed with the continued trend in taking advantage of hardware acceleration and your system’s GPU. Doug Purdy talked about OData and Bill Buxton talked design with an emphasis on what it really means to design for natural experiences.

Jason Brush from Schematic gave this presentation and it was focused on design of touch user experiences in a public setting, e.g. like kiosks or large screen wall type experiences. After recently getting an iPod Touch, I’ve become very interested in natural user interfaces (NUI) and it is quite fascinating (and obvious I guess) that you need to design differently for each of theses experiences. The basic message: design for the space that you will be in. Don’t forget the context of your application.

This session was presented by a trio of people from Blitz: a developer, a creative, and a user experience guy and its focus was how collaboration between all the disciplines can yield some amazing experiences. They talked about collaborating early and often and the mutual respect between disciplines required to make that happen. They also shared some of the practical methodology that Blitz uses, including how they brainstorm as a team. Another interesting thing they brought up was how they use the 6 human needs (significance, connection, certainty, variety, growth, and contribution) in order to craft immersive experiences.

This session was presented by an Irish fellow named Conor Brady of Organic. In it, he talked about Organic’s creative process and how they navigate the complex world of technology. One of the key things I was trying to get out of MIX personally was how other companies go about creating experiences and how they blend design and development in doing so … and so this session was right up my alley. Conor really knew his stuff and the experiences he shared were very cool, but it was a little too high level for my taste.

If you’ve never listened to Bill Buxton, you have to check this session out. He keynoted both last year and this year and is one of the most interesting people I’ve ever listened to. An influential designer on the world stage, he is also a principal researcher at Microsoft that is changing the company from within. He has a very engaging style: it is very laid-back and it’s like you’re talking to a friend or colleague. He was very keen on what he called BXT. BXT stands for Business, Experience, and Technology and he maintained that every team must have this trio of expertise and that they each must be on the same footing.

Yet another design/UX session that I attended. The main message here was of minimalism. Good design is hard, but it makes the complex … simple. That is, it is all about taking away. Once you can’t take anything else away, you’ve nailed it. This is a good message to internalize as a software developer for in my experience it is all too easy to keep cluttering up that user interface and creating a behemoth that scares (especially new) users and intimidates them.

This was another Open Call session voted in by the community and it didn’t disappoint. It was focused on the practicalities of how to create natural user interfaces (NUI) with multi-touch and using Silverlight and WPF 4. In fact, he even gave his presentation using some software that he created (that he called Natural Show). Definitely one of the better session at the conference.

In this session, Chris Bernard, a UX Evangelist at Microsoft went over how to use SketchFlow in order collaboratively sketch, prototype, and explore the user experience you are trying to create. This was a nitty-gritty session that personally exposed me to more of SketchFlow’s functionality. Chris did an amazing job and made several interesting claims about how useful SketchFlow is. The one that stands out is that he says that you should always be able to sketch up an animation faster in SketchFlow than doing it in code or xaml. He also said that you should start with SketchFlow animation before you use Blend behaviors. Great session and worth your time especially if you are new to SketchFlow like I am.

Above are the ones I most want to watch, but I’ll definitely want to take in some of the Windows Phone 7 ones as well as some of the Silverlight ones. So, here those are (for easy access for myself and others).