Click here to Skip to main content
Click here to Skip to main content

A Generic List and Dictionary Debugger Visualizer for VS.NET

By , 27 Aug 2011
 
ListVisualizer2008

Introduction

This is a simple List<T> and Dictionary<T,T> debugger visualizer for Visual Studio .NET 2005, 2008 and 2010. The only requirement for it to work is that the classes inside the lists or dictionaries should be marked as [Serializable].

Background

I used the nice article Create a Debugger Visualizer in 10 Lines of Code as a starting point. I recommend this article for further details on how to implement a custom debugger visualizer.

Using the Code

For installing the visualizer only, download the List Visualizer 2005, 2008 or 2010 according to the Visual Studio .NET version you would like to use. Run install_vs2005.cmd, install_vs2008.cmd or install_vs2010.cmd in a Visual Studio Command Prompt window. For Windows Vista, make sure to run the command prompt as Administrator.

Note that the Visual Studio path in the cmd files uses the default installation path, c:\Program Files\Microsoft Visual Studio 8 (for VS.NET 2005), c:\Program Files\Microsoft Visual Studio 9.0 (for VS.NET 2008) and c:\Program Files\Microsoft Visual Studio 10.0 (for VS.NET 2010). If you installed it in a different location, you might need to change the bat file and the post build events in the projects.

The default path for visualizers in 2005 is C:\Program Files\Microsoft Visual Studio 8\Common7\Packages\Debugger\Visualizers, in 2008 is c:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers and in 2010 is c:\Program Files\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\Visualizers. Just copy the assemblies there for a manual installation.

The source code contains both VS.NET 2005 (ListVisualizer.sln) and VS.NET 2008 solutions (ListVisualizer2008.sln). The post build event automatically deploys the visualizer for testing. Note that ListVisualizer2008.sln also contains the VS.NET 2005 projects that may be removed in case 2005 is not installed.

The source code for VS.NET 2010 can be found in a different zip file.

Points of Interest

I had to cast the generic types to non-generic interfaces to work with the variable that is being debugged:

// Get the list
IList list = (IList)objectProvider.GetObject();
 
// Get the dictionary
IDictionary dict = (IDictionary)objectProvider.GetObject();

After that, I used Reflection to retrieve object properties and fields to be displayed in the grid view:

// Retrieve the properties
PropertyInfo[] properties = singleObj.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
    dgvList.Columns.Add(property.Name, property.Name);
    columns.Add(property.Name, "P");
}
// Retrieve the fields
FieldInfo[] fields = singleObj.GetType().GetFields();
foreach (FieldInfo field in fields)
{
    dgvList.Columns.Add(field.Name, field.Name);
    columns.Add(field.Name, "F");
}

The solution contains six projects - the Dictionary Visualizer for 2005 and 2008, the List Visualizer for 2005 and 2008, the testing project ListVisualizerTest, and the class library that does most of the work, VisualizerLib. ListVisualizerTest is used to debug different types of Lists and Dictionaries and is also used to create the UI for the visualizers.

History

  • 15th April, 2008: Initial post
  • 3rd July, 2010: Article updated - created the new visualizer for Visual Studio 2010
  • 26th August, 2011: Article updated - visualizer for all Visual Studio versions can now be resized

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Daniel Carvalho Liedke
Software Developer (Senior)
Brazil Brazil
Member
I started development 22 years from now, since MSX basic. Started Windows programming with VB 2.0 and Web programming with ASP 3.0. Now I build Windows Forms, Web Applications, NT services and WPF applications using Microsoft.NET. I am MCP in Visual Basic 6.0, MCAD and MCSD.NET in Framework 1.1 ,MCPD Web in Framework 2.0, MCTS in .NET 3.5 workflow, MCTS in .NET 3.5 communication foundation and windows presentation foundation. Besides programming I love surfing.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
NewsHow to fix "Operation is not supported issue" when running the debuggermemberDaniel Carvalho Liedke14 Jan '13 - 8:12 
In case you get "Operation is not supported exception", make sure to unblock the dlls files with windows explorer right-clicking on the dll, properties, unblock before running the cmd file to install.
 
In case already installed, make sure to delete DLL files from C:\Program Files\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\Visualizers, unblock the dlls from zip and run install cmd command. Restart Visual Studio.Net if open.
 
Thanks! Big Grin | :-D
 
Daniel Liedke
Questionwhy need Serializablemembergrace&grace27 Jun '12 - 16:06 
if without Serializable, which step will it fail?
thanks, nice tool.
AnswerRe: why need SerializablememberDaniel Carvalho Liedke28 Jun '12 - 14:52 
Hello, it need the attribute to be able to send the object to VS.NET debugger infrastructure.
 
Thank you!
Questioncan't make it work v2010 x64membermikedepetris19 Jan '12 - 10:21 
I'm in Visual Studio 2010 on Windows 7 x64. All seems ok, put dlls in the right dir, tried to modify and test the projects, all is ok but the visualizer do not appear while debugging. It even works if I use the MS suggested:
public static void TestShowVisualizer(object objectToVisualize)
{
  VisualizerDevelopmentHost myHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(DebuggerSide));
  myHost.ShowVisualizer();
}
but the visualizer does not show in VS debug, I only get the typical useless ms interface to navigate the list.
AnswerRe: can't make it work v2010 x64memberDaniel Carvalho Liedke20 Jan '12 - 7:25 
Strange, I have the same configuration here.
 
Did you put the DLLs at C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\Visualizers?
 
Did you added the [Serializable] attribute in the business class?
 
Thanks!
QuestionForm is blank - no grid shownmemberjeff.harris165 Jan '12 - 3:47 
I would very much like to use this, but after installing on VS2010 on Windows 7, I cannot get it to work. The magnifying glass appears for lists in the locals window, but when clicked, I just get a blank form with no grid and no items. Any help is appreciated.
 
note: i have tried on both 32 and 64 bit machines after reading other posts on this forum.
AnswerRe: Form is blank - no grid shownmemberDaniel Carvalho Liedke6 Jan '12 - 12:13 
Hi!
 
Did you added the [Serializable] attribute in the class?
 
Also notice that for some complex objects it will not work, but Windows 7 32/64 bits are supported.
 
Thank you! Big Grin | :-D
GeneralRe: Form is blank - no grid shownmemberDavid Laub12320 Feb '13 - 10:38 
I have the same problem - blank form (Win 64) Yes, the business class is marked {Serializable] and the object is as plain POCO as it gets.
GeneralRe: Form is blank - no grid shownmemberDavid Laub12320 Feb '13 - 11:14 
never mind - it was the Serializable attribute - I forgot to deploy my dll to the proper bin dir - also NOT swallowing the exception in the core lib was essential.
SuggestionRemove Source Code Control and User FilesmemberAndy Missico8 Sep '11 - 4:22 
I suggest you remove the Visual SourceSafe files (.scc and .vspcc) and the Visual Studio user options files (.suo and .user) before packaging your source code archive.
GeneralRe: Remove Source Code Control and User FilesmemberDaniel Carvalho Liedke28 Dec '11 - 4:27 
Great suggestion, I will try to do it in next release if I remember.
 
Thanks!
QuestionImprovement + other visualizermemberI'm Chris29 Aug '11 - 23:00 
Hi Daniel,
 
I improved a little your visualizers (correctly dispose of the resources, made the form designable in VS...).
Furthermore, I created other visualizers: a byte array / memorystream visualizer and an image visualizer.
Do you want we put all these in a shared project (in CodePlex for instance)?
 
Regards
Chris
Chris
www.aulofee.com - Infrastructure and Security Supervision, Event Correlation

AnswerRe: Improvement + other visualizermemberDaniel Carvalho Liedke28 Dec '11 - 4:24 
Sure! Please send us the link later so we can check it out! Big Grin | :-D
 
Thank you!
GeneralRe: Improvement + other visualizermemberI'm Chris9 Jan '12 - 6:34 
Ok. So keep in touch. I'll first look for similar projects in CodePlex to avoid create a new one. Once done, I'll post the link here.
Chris
www.aulofee.com - Infrastructure and Security Supervision, Event Correlation

QuestionGreat! But why fix the output screen?memberOwin_wan_kenobi26 Aug '11 - 3:45 
Hi there,
 
Nice visualizer. But it is a shame that the output screen (at least of the List Visualizer) is very small and I cannot modify it.
AnswerRe: Great! But why fix the output screen?memberDaniel Carvalho Liedke26 Aug '11 - 5:05 
Agree! I will try to fix this and upload a new version soon.
Thanks for the suggestion! Smile | :)
GeneralRe: Great! But why fix the output screen?memberDaniel Carvalho Liedke26 Aug '11 - 7:39 
I implemented your suggestion and generated the install files for all Visual Studio versions. I already submitted it to Code Project, we just have to wait for them to update the article. Thank you! Big Grin | :-D
GeneralRe: Great! But why fix the output screen?memberDaniel Carvalho Liedke28 Aug '11 - 4:14 
Article updated. Thanks!
NewsDebugger Visualizer doesn't support C++\CLI.memberkas25 May '11 - 6:44 
Good article!
But pay attension, it seems, that Debugger Visualizer doesn't support C++\CLI. Proof Debugger Visualizer not shown when using CLI/C++
GeneralRe: Debugger Visualizer doesn't support C++\CLI.memberDaniel Carvalho Liedke25 May '11 - 13:07 
Thanks for the note! Big Grin | :-D
QuestionSilverlight Support?memberStepjan Hejne25 Jan '11 - 3:54 
Great tool!
I just tried it and it works well - with forms applications Wink | ;)
But my real goal is to debug dictionaries in Silverlight, but there no [Serializable]Attribute exists. Silverlight uses a [DataContract]Attribute but the Visualizer does not work with those attribute Frown | :-(
 
Any idea how I could use the Visualizer in Silverlight?
 
Thanks in advance!
AnswerRe: Silverlight Support?memberDaniel Carvalho Liedke25 Jan '11 - 7:53 
Hi, I researched lot but I couldn´t find a way to run it with Silverlight Frown | :(
 
Thank you!
GeneralError messagememberawstam6 Jan '11 - 0:15 
Hi,
 
Your visualizer seems like a very useful debugging aid. Unfortunately it doesn't work on my VS 2010 Professional.
I do get to see the magnifying glass when I hover over a generic list, but when I click on it I get:
 
System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\Visualizers\ListVisualizer2010.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\Visualizers\ListVisualizer2010.dll' ---> System.NotSupportedException:
 
An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
 
Any ideas how to fix this?
 
thx
GeneralRe: Error messagememberDaniel Carvalho Liedke6 Jan '11 - 1:38 
There are some ideas from this thread http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=17768[^]
 
- Unblock the dlls files and/or
- Grant permissions to your user
 
or
 
- Move it to directory My Documents\Visual Studio 2010\Visualizers
 
or
 
- Rebuild the sources with your own Visual Studio 2010
 
Thank you, I hope it solves the problem.
Generalx64 Runtime SupportmemberCitizenDC30 Dec '10 - 22:43 
Please note that this visualizer does not display the grid items when debugging an X64 application.
 
Best Regards,
 
Me

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 27 Aug 2011
Article Copyright 2008 by Daniel Carvalho Liedke
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid