Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify order of debugger visualizers in Visual Studio

I've been working on a debugger visualizer for Visual Studio for some time and while the actual visualizer works fine. The problem is that it always places itself at the top of the visualizer list when examining a variable which really annoys some of the users who rather have Text as the top one (since the top one is also default when opening VS).

enter image description here

I can't find any support for this on DialogDebuggerVisualizer or DebuggerVisualizerAttribute which were my first thoughts so I've been scouring SO/MSDN/Google for information on how to affect the sort order of the visualizers (preferably to put mine last in the list) but to no avail.

Below is how I register my visualizer, it then just shows a form based on the value that is being visualized.

using Microsoft.VisualStudio.DebuggerVisualizers;  [assembly: System.Diagnostics.DebuggerVisualizer(     typeof(Shorthand.VSAddins.JsonVisualizer.JsonVisualizer),     typeof(VisualizerObjectSource),     Target = typeof(string),     Description = "Json Visualizer")] namespace Shorthand.VSAddins.JsonVisualizer {     public class JsonVisualizer : DialogDebuggerVisualizer     {         protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)         {             var json = objectProvider.GetObject() as string;              var form = new VisualizerForm { Json = json };             windowService.ShowDialog(form);         }     } } 

Does anyone know if it is possible to affect the order of the visualizers or should I just let it be?

like image 962
Karl-Johan Sjögren Avatar asked Aug 27 '13 07:08

Karl-Johan Sjögren


People also ask

How do I change Debug in Visual Studio?

To set Visual Studio debugger options, select Tools > Options, and under Debugging select or deselect the boxes next to the General options. You can restore all default settings with Tools > Import and Export Settings > Reset all settings.

Where to put Natvis?

natvis files in the <VS Installation Folder>\Common7\Packages\Debugger\Visualizers folder. These files have visualization rules for many common types, and can serve as examples for writing visualizations for new types.

How do I enable debugging in Visual Studio?

In the Visual Studio toolbar, make sure the configuration is set to Debug. To start debugging, select the profile name in the toolbar, such as <project profile name>, IIS Express, or <IIS profile name> in the toolbar, select Start Debugging from the Debug menu, or press F5.

How do I Debug COM objects in Visual Studio?

In visual studio if you open tools >> Options and then debugging >> General make sure the option "Use managed compatibility mode" it checked on. This should show com objects as their proper types in the debugger.


1 Answers

I don't think there is a solution. But there is a workaround:

Define your own Text Visualizer and put appropriate DebuggerVisualizer attribute before the attribute of your JsonVisualizer. The result will be that string will be readable by default and Json Visualizer can be chosen. A window with a multi-line textbox is not too much work.

It is probably not even necessary to write visualizer. It should be possible to use internal one but I don't know its name (Which class is used for "Text Visualizer"?).

like image 166
IvanH Avatar answered Sep 20 '22 18:09

IvanH