title | description | ms.date | ms.topic | dev_langs | helpviewer_keywords | author | ms.author | manager | ms.subservice | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Test and Debug a Visualizer | Test and debug a visualizer by running it from a test driver (visualizer development host) or by installing in Visual Studio and calling it from a debugger window. | 07/02/2021 | how-to |
|
| mikejo5000 | mikejo | mijacobs | debug-diagnostics |
Once you have written a visualizer, you need to debug and test it.
One way to test a visualizer is by installing it in Visual Studio and calling it from a debugger window. (See How to: Install a Visualizer.) If you do that, you will need to use a second instance of Visual Studio to attach and debug the visualizer, which is running in the first instance of the debugger.
An easier way to debug a visualizer is to run the visualizer from a test driver. The visualizer APIs make it easy to create such a driver, which is called the visualizer development host.
Note
Currently, the test driver is supported only when calling the visualizer from a .NET Framework application.
In your debugger-side class, include a static method that creates a xref:Microsoft.VisualStudio.DebuggerVisualizers.VisualizerDevelopmentHost object and calls its show method:
publicstaticvoidTestShowVisualizer(objectobjectToVisualize){VisualizerDevelopmentHostmyHost=newVisualizerDevelopmentHost(objectToVisualize,typeof(DebuggerSide));myHost.ShowVisualizer();}
The parameters used to construct the host are the data object that will be shown in the visualizer (
objectToVisualize
) and the type of the debugger side class.Add the following statement to call
TestShowVisualizer
. If you created your visualizer in a class library, you need to create an executable to call the class library and place this statement in your executable:DebuggerSide.TestShowVisualizer(myString);
For a more complete example, see Walkthrough: Writing a Visualizer in C#.