Friday, January 28, 2011

Quickie: Unwrapping Invocation Exceptions

If you work with dynamic invocation in any way, shape or form you're bound to catch a TargetInvocationException at some time or another. However, the fact that the real exception has been wrapped into a TargetInvocationException can hide a multitude of sins - potentially all sorts of different exception types can get wrapped from all sorts of sources.

One further problem is that it's entirely possible to get nested TargetInvocationExeptions as the call stack unwinds - again masking what the real problem is. This was the precise situation I found myself in with my nicely crafted n-tier WCF-based system.

So to make life just a little easier on myself when dealing with the exceptions thrown whilst performing a dynamic invocation I put together the following extension methods - one that re-wraps an exception and one that un-wraps nested TargetInvocationExceptions.

To use it, we just catch and re-throw, except using the extension methods.
// Do something dangerous with dynamic invocation
catch (TargetInvocationException ex)
throw ex.UnwrapTargetInvocationExceptions().ForRethrowing();
What you'll get is an exception throw of the same type as the actual fault, regardless of how many nested TargetInvocationExceptions it is wrapped in. Because we're nicely wrapping the exception we also maintain the call stacks to let you trace what's really going on.

Finally, here's the source - use it at your own risk - I've found it handy!

public static class ExceptionExtensions
/// Returns an exception wrapping an exception, but of the same type a
/// that's exception's INNER exception.

/// This allows us to write code like
/// throw ex.InnerException.ForRethrowing()
/// to re-throw an inner exception type without losing the stack trace.
public static T ForRethrowing(
this T innerException, Exception outerException)
where T: Exception
var actualType = innerException.GetType();

var ctorParams = new object[] {
innerException.Message, outerException
var result = (T)Activator.CreateInstance(actualType, ctorParams);
return result;

/// Unwraps an exception from any wrapping target invocation exceptions.

public static Exception UnwrapTargetInvocationExceptions(
this Exception exception)
var innerException = exception.InnerException;

// not a TargetInvocationException, or no inner exception? Then
// just return the exception itself
if ((innerException == null) ||
(!(exception is TargetInvocationException)))
return exception;

return innerException.UnwrapTargetInvocationExceptions();

Monday, January 24, 2011

Getting it right - filming DDD WP7

OK, now they're all available I want describe how I filmed the Developer Developer Developer - WP7 event that was held back in October 2010 at The Printworks in Manchester.

As an entirely community driven event, the day provided 9 sessions that gave a really good introduction to WP7 development - including Andy Wigley's excellent talk on Tombstoning - with NO Microsoft presenters.

The videos are now all up on Channel 9, courtesy of Mike Ormond - and are all in HD to boot.
And now for the trumpet-blowing bit - I was the lunatic that volunteered to film, edit and produce all 6 hours of final video output.


I filmed the presenter using a Canon XM camera placed at the front of the auditorium - this gave me good footage of the presenter (although Rob Miles enthusiasm as he bounds around the stage makes tracking him a challenge!) as well as a master wide shot against which to synchronise the slide graphics.

A second, smaller Sony HD Handycam was placed in the middle of the back row of the cinema to get a "god's eye view" of proceedings, and to record the screens during demo's. This worked well, but I do think that a camera that has manual focus would have been better, and a direct feed recorded from the screen best of all. Unfortunately that last option requires a £500 converter and some kind of SDI recorder - well beyond the budget of this kind of community event.

Finally I had a second Sanyo HD Handycam for quick pick-up shots of the audience - this really needs a dedicated cameraman / interviewer to make best use of it. I used it in the breaks to get some shots of the outside area where Mike Ormond was running his XAPathon, but the light levels were really too low for any of the footage to be useful. Some of the in-auditorium shots were used as cut-aways in the final edit tho'.

Each presenter was given a second radio pack (in addition to the one for the venue SR system) that was recorded by the Canon - I had two packs, so there was no rushing to swap between presenters. These recorded a good clean audio track against the close-up video which would allow me to sync the recordings from both camera in the edit more easily.

The Sony camera's front stereo mics recorded a good "wild-track" of the audience (and the presenter's voice played through the SR speakers), but regretably the audience levels were never enough to get a clean recording of any questions. This audio did get used at low-levels in the mix to provide some room ambience.

I think the only way to improve the recording of audience questions would be to have 2 or 3 runners with radio stick mics ready to hand them out, or else use a couple of shotgun mics on long booms. That would also allow the question to be piped through the SR system so everyone could hear it clearly as well as allowing it to be recorded.

After the success of filming the Guathon, I wanted to once again get a really clean audio recording of the presenter. As the portable digital recorder I used before wasn't available I used a stereo 1/4" jack to USB audio interface to record the mix audio directly from the Sends of the SR mixing desk into a netbook running Sony Sound Forge Audio Studio. This worked superbly, giving a perfectly clear recording without having to worry about batteries or filling the CF card - seeing "196 hours available" gives a nice warm feeling!

Post Production

After the event, the footage from the Cannon was ingested into my Vaio laptop using a Sony HDV deck over Firewire. Footage from the handycams was pulled straight from the SD cards, and the audio files were just copied over the network from the Netbook onto the Vaio. Then came the hard work - editing in Sony Vegas.

I started by pulling in the master audio files - these were full-length for each session, so gave me a good place to start. Laying the Canon video/audio tracks alongside synchronised the audio for each clip, then did the same for the Sony Handycam footage. This gave me two video tracks (the close-up of the presenter and the "God's eye" view to work with whilst adding the slide graphics exported from Powerpoint as Png's.

Once each session was prepared, the video and slides were merged down into a "Multi-Camera Edit Track". This is a superb feature in Vegas, and lets you easily cut between the three shots as the video is playing. Once the cuts were finalised, it was just a matter of putting a 16 frame cross-fade between each shot, adding top and tail titles and rendering out as a Windows Media file.

Final file sizes were ranged from 700Mb to 1.5Gb per session - 720p targetting a 3.5Mb data rate.


This was where Mike Ormond came in - he'd most graciously offered to get the final videos up onto Channel 9 for distribution, and provided access to Microsoft's "big-file-upload" service. He then took each one, uploaded it to C9 for conversion and authored the associated blog posts that are linked above.

Final Thoughts

Was it worth doing?

Absolutely. The DDD sessions are always a superb resource on their subject matter, so allowing those that couldn't be there on the day to see them is highly valuable.

What would you do differently?

First, take a week off from my day-job to do the edit! Fitting this level of complex editing into late-nights and weekends when you've got a young family is hard.

Second, given a larger budget I'd have at least one other cameraman, a second Canon, boom operater / mic runners and record the screen output directly.

Thirdly, I'd try and have Rob Miles tied to the desk! His exuberance makes it damn hard to film as be bounds around and even harder to edit - but that's what makes him such an engaging presenter.

Thanks to everyone involved in setting up this event and letting me record it - may there be many more.

Another New Start

There are a couple of the reasons I've been so quiet on this blog. Firstly, Blogger was (until recently) blocked entirely at my workplace, making ad-hoc posts a pain; and secondly because Chris Alcock has done such a sterling job with "The Morning Brew" that my musings on .Net tidbits were entirely superflous (he well deserved his MVP for that).

But it's another New Year, Blogger has been unblocked at work, so I should really get on and post about some of the technical nuggets that have been stuck in limbo for the last year or more.

Time to dig into the internal blogs and wikis and pull out some nuggets.