Chin
Chin

Reputation: 20705

Visual Studio Text Visualizer missing text

I am debugging a string variable in Visual Studio using the Text Visualizer. However, it seems that a large part in the middle of the string is missing. What is the reason behind this?

enter image description here

Upvotes: 16

Views: 4519

Answers (3)

Chin
Chin

Reputation: 20705

The Text Visualizer in Visual Studio can only display about 32,700 characters. If your string is longer than that, it will automatically replaces the excess part in the middle of the string with ....

I found this out the hard way.

Edit: this seems to have been fixed in Update 2. If you're on Update 1, see Diamond's answer.

Upvotes: 20

Ɖiamond ǤeezeƦ
Ɖiamond ǤeezeƦ

Reputation: 3331

This is an issue that was introduced with Visual Studio 2015 Update 1 as reported here: https://connect.microsoft.com/VisualStudio/feedback/details/2016177/text-visualizer-misses-corrupts-text-in-long-strings.

Microsoft will have a permanent fix for this in the first update after Update 1. In the meantime, use the following workaround: You can set the length at which the Text Visualizer will truncate by adding a registry key. Use the following command to set the length to a larger number (example 250000):

reg add HKCU\Software\Microsoft\VisualStudio\14.0\Debugger /v TextVisualizerStringLimit /t REG_DWORD /d [number]

Alternatively use a previous version of Visual Studio if you have one installed.

Upvotes: 4

gurkini
gurkini

Reputation: 65

There is a solution here.

  1. Create new project Class Library
  2. Add new Form MessageForm with TextBox inside, check MaxLength and Multiline properties of TextBox.
  3. Add .cs file with folowing content:
using System;
using Microsoft.VisualStudio.DebuggerVisualizers;
using System.Windows.Forms;    
[assembly: System.Diagnostics.DebuggerVisualizer(
typeof(TextVisualizer.DebuggerSide),
typeof(VisualizerObjectSource),
Target = typeof(String),
Description = "My Visualizer")]
namespace TextVisualizer
{
    public class DebuggerSide : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            var message = new MessageForm();
            ((TextBox) message.Controls.Find("textbox1",false)[0]).Text = objectProvider.GetObject().ToString();
            message.ShowDialog();
        }
    }
}
  1. Build Project
  2. Locate the DLL that contains the visualizer you have built and copy the DLL to either of the following locations:
    • VisualStudioInstallPath\Common7\Packages\Debugger\Visualizers
    • My Documents\VisualStudioVersion\Visualizers

If you want to use a managed visualizer for remote debugging, copy the DLL to the same path on the remote computer. Restart the debugging session. For more information, see How to: Install a Visualizer.

Upvotes: 2

Related Questions