Search code examples
c#visual-studiovisual-studio-2022visual-studio-extensionsdebuggervisualizer

Visual Studio Debugger Visualizer Work's Only For One Object


I create my Debugger Visualizer for Visual Studio 2022 Community and I find out that Visual Studio can visualize only one object at a time. Is there a way to make Visual Studio Visualizer track more than one object of same type?

Or maybe something wrong with my Visual Studio? Maybe exists some magic property somewhere?

Example: Here is example:

example

As you can see, here two variables 'a' and 'b' (same type of 'string') and only one Text Visualizer. And I need to have two Visualizer for both 'a' and 'b'.


Solution

  • Now we know that for the same type, Visual Studio reopens the same toolwindow.

    I figured out that, when you create your Debugger Visualizer you need to specify DebuggerVisualizerProviderConfiguration constructor and this constructor takes objects of class VisualizerTargetType.

    You can specify same type .NET type (on image below, you can see that I specify 'string') but different titles ((1) through (4)) and Visual Studio will open individual tool windows when you click on 'View'.

    public override DebuggerVisualizerProviderConfiguration DebuggerVisualizerProviderConfiguration => new(
        new VisualizerTargetViewType("My Visualizer 5.1 (1)", typeof(string)),
        new VisualizerTargetViewType("My Visualizer 5.1 (2)", typeof(string)),
        new VisualizerTargetViewType("My Visualizer 5.1 (3)", typeof(string)),
        new VisualizerTargetViewType("My Visualizer 5.1 (4)", typeof(string)))
    {
        Style = VisualizerStyle.ToolWindow