Debugger Visualizer for Visual Basic

Posted by Blake on 3/17/2015

There are still things in Visual Studio as of 2013 that are available for C# but not for VB, not that you can't do it in VB. One that I ran across recently was there wasn't a "Debugger Visualizer" template for VB. The debugger visualizer template basically gives you the bones of what you need to add if you were going to add a visualizer into Visual Studio.

There are two references you'll need to do for the below code to work.

  1. System.Windows.Forms (if you include a form to visualize which you probably will)
  2. Microsoft.VisualStudio.DebuggerVisualizers

Here is a conversion in VB of a DialogDebuggerVisualizer (for a String) that I made from a C# source template that was working.


Imports System.Windows.Forms
Imports Microsoft.VisualStudio.DebuggerVisualizers

<Assembly: System.Diagnostics.DebuggerVisualizer(GetType(CharVisualizer), GetType(VisualizerObjectSource), Target:=GetType(System.String), Description:="Character Visualizer")>
Public Class CharVisualizer
    Inherits DialogDebuggerVisualizer

    Protected Overrides Sub Show(windowService As IDialogVisualizerService, objectProvider As IVisualizerObjectProvider)
        If windowService Is Nothing Then
            Throw New ArgumentNullException("windowService")
        End If

        If objectProvider Is Nothing Then
            Throw New ArgumentNullException("objectProvider")
        End If

        ' Get the item as a string (in our case, this would be whatever data type you're dealing with)
        Dim data As String = objectProvider.GetObject.ToString

        ' Show the data (or a form, or whatever you want to do)
    End Sub

    Public Shared Sub TestShowVisualizer(objectToVisualize As Object)
	' This is shared so that it can be called with instantiating this class.
        Dim visualizerHost As New VisualizerDevelopmentHost(objectToVisualize, GetType(CharVisualizer))
    End Sub

End Class