3

I have created a debugger visualizer in VS2008. There are two classes i've made, in the same .dll :-

  • BinaryDataDebuggerVisualizer
  • ImageDebuggerVisualizer

The image one works fine (eg. the magnify glass appears in debug mode) but not for the byte[] one (BinaryDataDV). What my visualizer does is display the binary data as an image in a modal window (if the data is a legit image). I compiled to code in Release mode, then dropped the .dll into C:\Users\\Documents\Visual Studio 2008\Visualizers

this is the code that i used to 'define' the vis...

using

System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;
using Foo.DebuggerVisualizers;  

[assembly: DebuggerVisualizer(
    typeof (BinaryDataDebuggerVisualizer),
    typeof (VisualizerObjectSource),
    Target = typeof (byte[]),
    Description = "Binary Data to Image Visualizer")]

namespace Foo.DebuggerVisualizers
{
    public class BinaryDataDebuggerVisualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService,
           IVisualizerObjectProvider objectProvider)
        {
            ... my code in here
        }
     }
}

I've made a unit test in the debugger visualizer solution, which fires up and test the code .. which it correctly shows a legit (and also illegal) image files. so i believe the code is ok.

When i'm in my real solution, this is what i'm doing (where i expect the magnify glass to show, when i'm hovering over the variable in debug mode).

byte[] data = File.ReadAllBytes("Chick.jpg");

then i hover over the variable data when i've paused the code while debugging, on that line (using a breakpoint).

No hourglass :(

anyone have any ideas to what is wrong?

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

2 Answers2

9

Unfortunately this is not possible. There is a limitation in the Debugger Visualizer framework that prevents them from functioning on array types or object.

http://msdn.microsoft.com/en-us/library/e2zc529c.aspx

Quote from the page:

"You can write a custom visualizer for an object of any managed class except for Object or Array"

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • Thanks heaps for the answer. Wowzer! out of all the viz's i tried to do, it was one of them that wasn't supported! so lol :P thanks heaps JaredPar for the answer! – Pure.Krome Dec 06 '08 at 11:04
0

A workaround is described here: https://joshsmithonwpf.wordpress.com/2008/01/ written by Josh Smith.

In that article he was describing the use of a particular visualizer (called Mole, which no longer seems to exist); I've cut down that text somewhat to just leave the general purpose concepts.

...

The crux of the matter is that Visual Studio will not allow us to apply the DebuggerVisualizer attribute to [a custom visualizer] and specify that it works for any object that descends from System.Object. ... I figured out a simple way to work around this artificial limitation imposed by Visual Studio.

Visual Studio has no qualms with allowing us to specify that [a custom visualizer] can be used to visualize a System.WeakReference object. Since WeakReference is basically just a thin wrapper around any object, we use WeakReference as a Trojan horse to smuggle any object past the Visual Studio sentries... Once [the custom visualizer] gets a hold of the WeakReference we wrapped around the object that we actually want to visualize, it unwraps the object and displays it in the UI, throwing away the WeakReference in the process. Keep in mind that we are only using WeakReference as a container to smuggle any object into [the visualizer], we are not using that class for its intended and documented purpose.

So that’s all well and good, but it would be a real nuisance if you had to stop your debugging session just to edit your code and create these WeakReferences... That’s where the Watch window enters the picture. You can create a WeakReference in the Watch window, and pass the object to visualize into its constructor. Here’s an example...:

enter image description here

Once the WeakReference has been created in the Watch window, I can simply click on the magnifying glass icon to open [the visualizer].

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81