http://msdn.microsoft.com/en-us/library/ms164759
Edition
Express Pro, Premium, and Ultimate
Visual Basic
C#
F#
C++
Web Developer
This walkthrough shows how to write a simple visualizer by using C#. The visualizer you will create in this walkthrough displays the contents of a string using a Windows forms message box. This simple string visualizer is not especially useful in itself, but it shows the basic steps that you must follow to create more useful visualizers for other data types.
Note
The dialog boxes and menu commands you see might differ from those described in Help, depending on your active settings or edition. To change your settings, go to the Tools menu and choose Import and Export Settings. For more information, see Working with Settings. Visualizer code must be placed in a DLL, which will be read by the debugger. Therefore, the first step is to create a Class Library project for the DLL.
Note
1 of 6
5/25/2012 11:39 AM
http://msdn.microsoft.com/en-us/library/ms164759
Visual Studio automatically changes the class declaration in DebuggerSide.cs to match the new file name. 3. In Solution Explorer, right-click References and choose Add Reference on the shortcut menu. 4. In the Add Reference dialog box, on the .NET tab, choose Microsoft.VisualStudio.DebuggerVisualizers.DLL. 5. Click OK. 6. In DebuggerSide.cs, add the following statement to the using statements:
using Microsoft.VisualStudio.DebuggerVisualizers; Now you are ready to create the debugger-side code. This is the code that runs within the debugger to display the information that you want to visualize. First, you have to change the declaration of the DebuggerSide object so that inherits from the base class DialogDebuggerVisualizer.
DialogDebuggerVisualizer has one abstract method (Show) that you must override.
override protected void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider obj { } The Show method contains the code that actually creates the visualizer dialog box or other user interface and displays the information that has been passed to the visualizer from the debugger. You must add the code that creates the dialog box and displays the information. In this walkthrough, you will do this using a Windows forms message box. First, you must add a reference and using statement for System.Windows.Forms.
To add System.Windows.Forms
1. In Solution Explorer, right-click References and choose Add Reference on the shortcut menu.
2 of 6
5/25/2012 11:39 AM
http://msdn.microsoft.com/en-us/library/ms164759
2. In the Add Reference dialog box, on the .NET tab, choose System.Windows.Forms.DLL. 3. Click OK. 4. In DebuggerSide.cs, add the following statement to the using statements:
using System.Windows.Forms; Now, you will add some code to create and show the user interface for your visualizer. Because this is your first visualizer, we will keep the user interface simple and use a Message Box.
MessageBox.Show(objectProvider.GetObject().ToString()); This example code does not include error handling. You should include error handling in a real visualizer or any other kind of application. 2. On the Build menu, choose Build MyFirstVisualizer. The project should build successfully. Correct any build errors before continuing. That is the end of the debugger side code. There is one more step, however; the attribute that tells the debuggee side which collection of classes comprises the visualizer.
[assembly:System.Diagnostics.DebuggerVisualizer( typeof(MyFirstVisualizer.DebuggerSide), typeof(VisualizerObjectSource), Target = typeof(System.String), Description = "My First Visualizer")] 2. On the Build menu, choose Build MyFirstVisualizer. The project should build successfully. Correct any build errors before continuing. At this point, your first visualizer is finished. If you have followed the steps correctly, you can build the visualizer and install it into Visual Studio. Before you install a visualizer into Visual Studio, however, you should test it to make sure that it runs correctly. You will now create a test harness to run the visualizer without installing it into Visual Studio.
3 of 6
5/25/2012 11:39 AM
http://msdn.microsoft.com/en-us/library/ms164759
2. On the Build menu, choose Build MyFirstVisualizer. The project should build successfully. Correct any build errors before continuing. Next, you must create an executable project to call your visualizer DLL. For simplicity, we will use a Console Application project.
4 of 6
5/25/2012 11:39 AM
http://msdn.microsoft.com/en-us/library/ms164759
String myString = "Hello, World"; DebuggerSide.TestShowVisualizer(myString); Now, you are ready to test your first visualizer.
See Also
5 of 6 5/25/2012 11:39 AM
http://msdn.microsoft.com/en-us/library/ms164759
Tasks How to: Install a Visualizer Concepts Visualizer Architecture Other Resources Visualizers
Yes
No
Community Content
2012 Microsoft. All rights reserved.
6 of 6
5/25/2012 11:39 AM