Visualizers For Web Debugging

Friday, January 13, 2006

Visual Studio 2005 ships with a few handy visualizers for debugging. A visualizer presents a tailored view of an object, which is useful when an object is too complex to fit in a watch window or data tip. Custom visualizers can plug into Visual Studio, see “How To: Write a Visualizer” as a starting point.

control tree debugging visualizer

I’ve packaged up a couple custom visualizers I’ve used recently into a project: WebVisualizers.zip. The ControlTree visualizer shows the hierarchical relationship of web controls, starting with the visualized control at the top. For instance, if you hover over a this reference inside a web form class, and click the magnifying glass that appears, you’ll see all the controls on a form.

Controls implementing the INamingContainer interface appear in red. This visualizer was helpful in tracking down a misuse of FindControl. The second visualizer in the project will display an HttpCookieCollection in a grid view.

To install the a visualizer you have to build the source code. You can build with  Visual Studio, or from the command line “msbuild OdeToCode.WebVisualizers.csproj”, assuming msbuild.exe is in the path. Copy the .dll from underneath the bin directory into “MyDocuments\Visual Studio 2005\Visualizers”. VS.NET will automatically load the assembly when debugging, and inspect the metadata inside to know what types to visualize. Note: custom visualizers won't load for a web site running at less than full trust.

These Visualizers here are relatively simple. Brett Johnson wrote a visualizer for the ASP.NET cache, and a wicked-cool visualizer to render controls.


Comments
Roy Friday, January 13, 2006
Very nice. I had the same problem a while back when I was creating dynamic controls in ASP.NET...I ended up writing a recursive function that shows all the controls in the control tree along with their ids and value right on the web page.

Made 2 versions. One for the complete webpage. And one where you it takes in the parent control and it fetches all its children along with values...so had to do type checking on the such controls like "is it a date picker?" or a "drop down list?", etc.

Nice to see someone made a GUI version.
Scott Mitchell Friday, January 13, 2006
Very cool, I think this will be helpful in teaching students about the control hierarchy.

Thanks for releasing the source code, looking into these visualizers has long been on my TODO plate. I went ahead and tinkered with your code and had it so that the control hierarchy displays the properties for each control, and their values. (The reflection adds a bit of a lag for particularly large control hierarchies, though, at least in testing on my computer.)

I uploaded my code changes and posted them on my blog - http://scottonwriting.net/sowblog/posts/4963.aspx

Thanks again.
Tarun Tuesday, January 17, 2006
Hi Scott,
Great post, i downloaded the the code, copied at specified location, created a file system based web site in visual studio 2005.
Tried but not able to make it. I dont know whats wrong. Also, please tell me what is this indicated to
"Note: custom visualizers won't load for a web site running at less than full trust."

Regards
Peter Mounce Thursday, January 19, 2006
When I tried to use it, I got an exception as follows:

************** Exception Text **************
Microsoft.VisualStudio.DebuggerVisualizers.DebugViewerShim.RemoteObjectSourceException: Could not load file or assembly 'file:///C:\Documents and Settings\pmoun\My Documents\Visual Studio 2005\Visualizers\OdeToCode.WebVisualizers.dll' or one of its dependencies. Access is denied. ---> System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Documents and Settings\pmoun\My Documents\Visual Studio 2005\Visualizers\OdeToCode.WebVisualizers.dll' or one of its dependencies. Access is denied.

I assume this is because my Visualizers directory lacks an ACL (I've messed with that directory's location on and off a network share since I installed VS2005).

Which users/groups should have access for visualizers to work?

Note that I am attempting to use the Visualizer to debug a strong-named web application. I have compiled the Visualizer to have a strong-name too.
Peter Mounce Friday, January 20, 2006
Fixed it. My worker process doesn't run as the default account.
scott Sunday, January 22, 2006
Glad to hear you found the problem, Peter. Re your last question, your web app has to run at full trust to debug with custom visualizers. If you have <trust level="anything but FullTrust"> then the debugger can't load the visualizer.
Paul H Monday, February 20, 2006
I am getting the "Access Denied" exception when trying to use the visualizer also. The web.config.default has the default trust level at "Full". I also tried <trust level="Full" originUrl="" /> explicitly in my web.config to no avail. My web site runs under the default IUSR_COMPUTERNAME account. What else could be the issue?
dominick Tuesday, February 21, 2006
a cheap way of getting to the same info is using page tracing btw...
scott Tuesday, February 28, 2006
Dominick:

Right, but you have to wait for the page to render (which is too late in some scenarios).
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!