Visual Studio Debugger Visualizers (Take Two)
Sep
3
Written by:
Friday, September 03, 2010 9:53 PM
Do you have some Visual Studio debugger visualizers that worked in VS 2008 but don't work in 2010? Are you getting an unhandled exception that cannot cast your custom object to an ImageDebuggerVisualizer object? I (hopefully) have the quick fix for you!
When I upgraded to Visual Studio 2010, I forgot about my custom image Debugger Visualizer. DOH! Well, last week, I remembered and when I tried to "install" it (copy the assembly) I was met with a nasty, scary and unfriendly uncaught exception! DOH! Oh man! After 10-15 minutes of trying to figure it out, I realized this was going to take some more sleuthing than what I could afford that day.
Fast forward to tonight and I have more time. I started with last year's blog post and code I created last October (Visual Studio Debugger Visualizers are VERY cool! You gotta check this out!), fixed the problems with where the DebuggerVisualizer assembly needs to be copied to.
Normally to create/edit your custom DebuggerVisualizers you need to run VS as administrator privs. BUT! With VS 2010, on Windows 7, you can actually copy the assembly you need to
C:\Users\USERNAME\Documents\Visual Studio 2010\Visualizers
In fact, in the sample solution I have here, there's a Build Event which will automagically copy the compiled assembly to the correct directory for immediate use! Very cool eh? I encourage you to check it out!
The ONLY down side to doing it this way, is if you're sharing your machine with other people, either they ALSO have to copy the DLL to their Users directories, OR, you can alternatively do what VS 2008 used, and copy the assembly to the more global referenced directory. On x64 machines (note the x86 in the directory name, VS is still a 32bit application) the assembly goes in
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\Visualizers
It's COMPLETELY up to you where you want to put the assembly DLL. If you put it in the Users subdirs, then you get away without having to start VS as Administrator, but you can't share it. If you put it in the Program Files sub directories, you have to have gain write privs but everyone can use it. Your call. Me? I'm using the Users directory cause it's MUCH easier to update and deploy it, and I'm lucky enough to be the only geek on my machine (phew! LOL).
Next, once I loaded up my VS 2008 solution and upgraded it to VS 2010, then ran it, BOOM! I got the exception shown below. As you can see, to paraphrase (and help others googling for it) Unhandled exception has occurred in a component in your application...Unable to cast object of type 'blah.blah.blah.ImageDebuggerVisualizer' to 'Microsoft.VisualStudio.DebuggerVisualizers.DialogDebuggerVisualizer'.

There were two problems I had to fix. GREAT! Compound problems are the worst aren't they? When you fix something you're still left with it not working and you never really quite know if the FIRST thing you did is helping or hindering you?
Anyways, the first bug had to do with the placement of the VisualizerDebugger assembly DLL. But from above, you now know where it goes. The next bug had to do with the referenced DebuggerVisualizers assembly. DOH! I completely forgot about that, and never even THOUGHT that might be causing me a problem. But a couple of blogs eluded to this being the problem, but a blog by Andrew Smith, Josh Smith and Karl Shifflett confirmed it. If you're seeing this exception, check out the DebuggerVisualizers Version, if it's 9, you need to update it!

hhhhmmmm Next question is where IS the updated DebuggerVisualizers assembly? Check out this directory, C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0.

Once you do that, run the test project, it has a Debugger.Break() so you can quick test it out. If you see the magnifying glass, click it and you SHOULD see your custom debugger visualizer, just like mine! LOL

Now that you know how to fix your custom debugger visualizers, it's time to grab a coffee and get coding!
Resources:
Source Code: http://www.pchenry.com:8080/svn/blog/trunk/2010/ImageDebuggerVisualizer
PCHenry.com: Visual Studio Debugger Visualizers are VERY cool! You gotta check this out!
The Code Project: Mole For Visual Studio - With Editing - Visualize All Project Types by Andrew Smith, Josh Smith and Karl Shifflett