Dan Maharry

Thoughts on Presenting

by

On Monday I gave a presentation at my local user group and I know I can do better. I know this every time I do it. Here’s my post mortem then on what went well and what didn't.

  • Have Enough Material
    Make sure you know how long your session is and have enough material for it. Keep an eye on the clock as you go through the session so you can speed up or add a bit more material as required. If you over-run, know where you can stop early and skip to the conclusion.
  • Take Backups of Everything
    If you're doing demos, be prepared in case the demo gods are angry and decide to throw you a curveball. Save a copy of your code as it needs to be at the start of the demo and as it should look at the end of the demo. Then take separate copies on a USB stick as well in case your laptop dies on you. If you're using VS snippets take a back up of those as well. After connecting to the projector last night, my copy of VS decided I had never run it before and reset itself. Oh that I had taken a backup of those settings and snippets.
  • Projectors are not your friend
    • If possible, find out in advance what resolution the projector being used prefers and try running your presentation and demos in that resolution. Last night's projector gave a 4:3 image while my display is 16:9 resulting in a rather squashed look on my mirrored display in favour of the attendees having the better picture.
    • Make sure your demos can be shown without too much scrolling in the resolution you'll be using
    • Also check in advance what connections the projector uses. The user group should be able to cover it, but it never hurts to be prepared with your own cables.
  • Get There Early And Get Comfortable
    • Make sure you are comfortable with your setup before you start. Get there early, set up and run through a quick demo to make sure nothing untoward has happened in transit.
    • Don't be surprised if something does go wrong in a demo, but know in advance how to get out of it if something untoward should happen. Know that you can get yourself back on track (you did take backups of your demo code didn't you?)
    • Pack a USB keyboard light in case, like me last night, you find yourself trying to type purely by the light of your display.
  • Be Positive
    Don't be too negative unless that's part and parcel of your presentation.
  • Don’t Let The floor Lead You
    Know your subject well enough to field questions from the floor but don't be afraid to ask your interrogator to come and talk after the session if the answer would hold up your talk or digresses from it, else you’ll over-run.

I hope you find these points useful when you have a go and present a session yourself.

Debugging ViewState Errors & Visual Studio Debugging Options

by

(In which a problem with ViewState is solved by tweaking Visual Studio’s debugging options and using ViewState Decoder to locate the problem on the page)

When an error occurs in your code as you run it through the Visual Studio Debugger, you’ll know all too well that Visual Studio is given focus, opens the code file where the error has occurred and highlights the line it has occurred on. Recently, I came across the problem where as soon as I caused a page to postback, a ViewState error was instantly thrown before any of my code had run.

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request. 

Now typically if you see this error, you start searching your code for the phrase ‘Controls.Add’ because the error implies that you have changed the structure of the page after the state of the page has been saved into the StateBag. Statements like Page.Controls.Add(…) are the usual culprits as this is exactly what they do. However, there were no such statements in my entire site, let alone this particular page.

To discover the exact problem then, I told the debugger to show me every error that occurred, not just the ones in my code as follows

  1. In Visual Studio, select Tools > Options > Debugging > General
  2. Uncheck “Enable Just My Code (Managed only)” and hit OK.
    The VS2008 Debuggin Options Dialog
  3. Press Ctrl + Alt + E to bring up the Exceptions dialog. This allows you to specify which errors the debugger should break to code on encountering. Check ‘Common Language Runtime Exceptions’ to break on any .NET Exception. Drill down into the tree to be more specific – e.g. to break only those Exceptions in the System namespace. Hit OK.
    VS_Exception_Dialogs2

Debugging into the page again, the debugger quickly identified a System.InvalidCastException occurring with the message

{"Unable to cast object of type 'System.String[]' to type 'System.Collections.ArrayList'."}  when System.Web.UI.StateBag.LoadViewState(Object state)  is being called.

After clicking continue, the ‘Failed To Load Viewstate Error’ then appeared and we were back to the error we’d seen before. All the InvalidCastException message tells us is that as the server loaded the viewstate from the page back into the pipeline for processing, it expected an ArrayList and got a String array instead. By inspecting the page’s viewstate then, we could investigate where this clash might be occurring and try to map it to the page.

Enter Fritz Onion’s ViewState Decoder app, a really handy download which takes that encoded hidden field on your page and renders it into something more legible. Loading my erroring page into the decoder presented me with the following.

Screenshot of Viewstate Decoder displaying the viewstate from the erroring page. Highlighted is the only string array in the viewstate

As luck would have, it turned out there was only one string array in the entire viewstate tree (highlighted above) and that highlighted this line in the markup was the likely cause

<script type="text/javascript" 
src="<%# ResolveUrl("~/scripts/swfobject.js") %>">
</script>

and in the code-behind, this line in Page_Load, which ensured any javascript urls in the page header are resolved, was the malfeasant one.

Page.Header.DataBind();

Sure enough, commenting out the call to DataBind() stopped the ViewState error occuring on the page, but the location of the script in the header was not resolved. Rather than using an absolute URL, I ended up opting for a Literal control which generated the correct script tag instead and all was well.

A New Book : Using Gallio & MbUnit

by

With the documentation for MbUnit v2 done and dusted last year, thoughts turn to missives and tutorials for MbUnit v3 and the Gallio platform. Jeff and the team have done a huge amount of work maintaining the API documentation as they’ve gone along, but the book project that has always been planned is a bit thin on the ground.

With Gallio/MbUnit v3.1 close around the corner then, we’ve decided to reboot the Gallio Book project and made a new outline for the first part of the book – Using MbUnit & Gallio – which you can view here. We’ve also created a new Google group for the Book project. Anyone who’d be interested in writing, reviewing the book should join the group and get in touch. If you’d just like to suggest content to be included in the book, again either join the group, or leave a comment. We’ve also got a basic progress chart for the book where you can check progress on the chapters you are most interested in.

If you know MbUnit or indeed if you don’t, consider getting involved, learning the tool and learning how the book process works. It’s just about hacking words and pictures instead of code. Hopefully I’ll see some of you at Gallio-Book.

WebDD 2009

by

Saturday morning saw the second free WebDD conference take place. Amongst the presentations, Mike Ormond and Alex Mackey spoke on things forthcoming in .NET 4.0, Sebastien Lambla spoke at a rate of knots about MVC best practices despite his computer blue-screening mid-presentation, and I introduced those interested to IIS 7.0 Extensions, the Lightweight Test Framework, the new ASP.NET Chart Control and the History State and Script Combining features of the ScriptManager. The code and slides for this presentation can be found here and via the downloads page.

Thanks to Dave and to Phil for setting up WebDD, the speakers, attendees and MS event staff for giving up their Saturday to make this a great event and finally to Janey for coming to support me while I tried not to um or ah too much through my first presentation. If you’ve any feedback for me on how I went, let me know or twitter it using the #webdd tag.

WebDD 2009

by

Saturday morning saw the second free WebDD conference take place. Amongst the presentations, Mike Ormond and Alex Mackey spoke on things forthcoming in .NET 4.0, Sebastien Lambla spoke at a rate of knots about MVC best practices despite his computer blue-screening mid-presentation, and I introduced those interested to IIS 7.0 Extensions, the Lightweight Test Framework, the new ASP.NET Chart Control and the History State and Script Combining features of the ScriptManager. The code and slides for this presentation can be found here and via the downloads page.

Thanks to Dave and to Phil for setting up WebDD, the speakers, attendees and MS event staff for giving up their Saturday to make this a great event and finally to Janey for coming to support me while I tried not to um or ah too much through my first presentation. If you’ve any feedback for me on how I went, let me know or twitter it using the #webdd tag.