Thursday, 1 January 2015

Introducing Threepio!

I saw this a few weeks ago and thought 'That might be interesting', since it seems to combine two of my favourite things, Star Wars and code, so I signed up. On 21st December beta access to the API was opened up, and I started having a look at it. Almost immediately, a set of helper libraries appeared for different stacks (Javascript, Ruby, even PHP), but none for .net. So I sprang into action (well, it was more of a lurch really) and started to put together some C#, and over the Christmas break I've finished it (or at least I have it at a point where I'm prepared for other people to look at it).

It's written in C(#), and it translates from JSON into .net objects, so I had to call it Threepio...

The code is on Github at

Things I want to look at/think about doing:

  • Should the GetPage methods return IEnumerable instead of List?
  • The Get(id) methods throw an exception if you call them with an invalid id, inline with this which I read yesterday would it be better to change them to TryGet?
  • Putting up a Nuget package.

Sunday, 13 April 2014

Book Clearout

I had a tidy-up and spring clean of my home office yesterday, and I cleared a lot of books of my shelves. Before they go to the tip for recycling, here's a list of what I cleared. If anyone wants any of these, let me know by 18th April.

A Programmers Introduction to C#, Eric Gunnerson
Visual C# Language Reference
Programming ASP.NET 2.0 Advanced Topics 2005 Ed, Dino Esposito
Debugging .NET 2.0 Apps, John Robbins
Javascript: The Definitive Guide 4th Ed, David Flanagan
ASP.NET 2.0 Cookbook, Geoffrey LeBlond
Essential ASP.NET 2.0, Fritz Onion
nHibernate in Action, Pierre Kuate
ASP.NET 2.0 Server Control & Component Development, Shahram Khosravi
The Definitive Guide to The Microsoft Enterprise Library, Keenan Newton
ASP.NET 2.0 Anthology, Jeff Atwood
ADO.NET & ADO Examples and Best Practices, Bill Vaughn
Pro ASP.NET MVC 1.0, Scott Hanselman
Building a Web 2.0 Portal w/ASP.NET 3.5, Omar Al-Zabir
Designing and Developing Web-Based Applications Using the .NET Framework, Mike Snell
Distributed .NET Programming in VB.NET, Tom Barnaby
Applied ADO.NET, Mahesh Chand
Developing ASP.NET Server Controls & Components, Nikhil Kothari
Enterprise Development with Visual Studio.NET, UML & MSF, John Erik Hansen
Inside VS.NET 2003, Brian Johnson

Wednesday, 19 February 2014

64-bit Considered Harmful...

Thought I should write about a problem I ran into last month in the hope that it saves someone else some heartache (or potentially someone tells me how to fix it...)

A few weeks ago, while I was searching for something else in Visual Studio's Settings, I ran across this option:
I run on 64-bit Windows, so I figured this would be a sensible option to set and switched it on. And all was good in the world.

Until I started on a new project a couple of weeks later, that is, when running it up for the first time I was puzzled to see this YSOD:
Invalid program? What the hell's that coming from? The only thing that I could immediately think of was that the last thing I did before hitting F5 was to install Ninject. I cast around for an hour or so trying assorted types of restarting processes/PCs etc, before going to Twitter...

Fran quickly replied with this:

which was the clue I needed:
And yep, as soon as I turned off 64-bit IIS Express the world righted itself...

So I'm interested to know what causes this and whether there's a way to successfully run Ninject in 64-bit code (I'm quite prepared for this to be something related to my inexperience with Ninject).

Friday, 16 March 2012


What’s A GiveCamp? 
I spent the weekend of 21st-23rd October last year working for charity at GiveCamp. What’s a GiveCamp? Givecamp is an event where technology experts give their time over a weekend to build projects for charities. It’s funded by corporate sponsorship, which means it’s free to attend for both the charities and the volunteers. The concept originates from Microsoft in Texas in 2007 – since then over $1m worth of time and consultancy has been donated. In 2011, GiveCamp UK was the first GiveCamp to be held outside the USA. I got involved through knowing the organisers; many of my friends from the UK Microsoft programming community were also there. 

How Does It Work? 
We assembled at UCL’s Bloomsbury Campus on the afternoon of 21st October, where there was a chance for a cup of coffee and a gossip with people while we waited to find out where we needed to be. At about 5pm we all trooped into a lecture theatre, where representatives from a set of charities each delivered a short pitch about their charity, and more importantly, the project they wanted people to tackle over the weekend. In the main room, there was a chance to speak to the charity reps again to get more detail on their project, and everybody gradually organised themselves into teams. 
I chose to work with a charity called Scene And Heard , who run playwriting courses for children – the plays the children write are then performed by volunteer professional actors. The project that Scene And Heard pitched for was to build them a ticketing system. As we got into the detail of their requirements, we all realised that rather than building a system for them ourselves, we could set them up with an account on EventBrite, which is a website that provides ticketing services for events. And EventBrite wouldn’t cost them anything to use. Score! And even better, at that point the catered dinner arrived! 
Having such a quick and easy win for us was a great boost for our team, and, fortified by yummy sausages and mash, it meant we could go back to Scene And Heard and say ‘what else can we do for you?’. It transpired that they were managing their lists of volunteers, plays and performances in a set of Excel spreadsheets and, in their own words ‘a car-crash Access database’. This, then, would be our project for the rest of the weekend – to meld all these elements into a single, web-based database. We started to explore some initial options using a new Microsoft technology called Lightswitch up to about midnight on Friday night. 
On Saturday morning we arrived back at our table in dribs and drabs, but were greeted by a cornucopia of bacon sandwiches, sausage sandwiches and pastries! I found I’d made exactly the right decision to stay at the Premier Inn round the corner – some people had elected to take the ‘camp’ part of GiveCamp quite seriously and there was a large room full of tents and sleeping bags, however it seemed that one of the campers was an epic snorer, and there were several bleary-eyed developers to be seen. 
Fuelled by the aforementioned breakfast and endless cups of coffee and tea, we were all back at our table and working by 10am, however we were all starting to struggle with problems with Lightswitch, in part because none of us had used it before. After a lunch of delicious burritos, at about 2pm, we had a stand-up where we reviewed the progress we’d made and discussed the problems we were having (a stand-up is a short project status meeting (that is held standing up to remind people to keep the meeting short)). 
The various problems we were having with Lightswitch were killing our productivity, so we took the decision to throw it all away and switch to a different style of web development. This meant we would be up against it to get things delivered, but crucially the switch meant we could all be much more productive and we started to see the benefits almost straight away. We worked into the night, stopping only for pizza and the odd bottle of beer, but by 2am we were all flagging badly and agreed to call it a night. 
Sunday morning was the home stretch – the cutoff for all teams was midday, which was probably just as well as otherwise we’d all have kept going until UCL kicked us out. We still had loads to do however, and I was back at our table at 8am, typing with one hand and eating a pain au chocolat with the other. We continued to make steady progress and integrate the different pieces of work we’d all been doing, right up to 12, and we agreed to continue to work on the project after the weekend in our own time to complete the parts we’d been unable to finish. There were a couple of hours to decompress and chat to other teams to see how they’d been getting on, before we all trooped across the road into a lecture theatre so each team could present on what they’d been doing. (You can see Dan Elliott’s presentation on the You Can Hub project through the medium of interpretive dance at Our new friends from Scene And Heard were thrilled with how much we’d been able to accomplish in less than two days – ‘you’ve changed people’s lives’ was their reaction, and there were several people with tears in their eyes. Not me, I just had something in my eye. Honest. 
All the projects were seriously impressive, everybody had worked flat out all weekend and many people had learned on the spot things they’d never needed before, from integrating YouTube into a website, to using EventBrite like us, to building a CRM system in a weekend. There was a prizegiving ceremony - many companies had donated prizes to be given out, and courtesy of the Charity Technology Trust everyone received a brand new solid-state disc drive for their laptop – before it was time to say our farewells and head home for some much-needed sleep. As GiveCamp was held over a weekend, I was able to use my WSP volunteering days to take two days off afterwards to recover! 

What Did I Learn? 
As well as picking up some techniques for recording and managing project requirements and measuring progress, my biggest takeaway from GiveCamp was the importance of flagging up project concerns early. Our decision to try Lightswitch cost us over half a day, which in a time-critical situation like this was time we couldn’t afford, when I’m not sure any of us was absolutely convinced it was the right thing to do. My other takeaway is how much can be done in just two days; for an individual, it’s difficult to achieve anything substantial in such a short space of time, but a team of highly skilled and motivated people working together for a couple of days can deliver impressive results. I’m already looking forward to seeing what we can do at GiveCamp 2012. 

Friday, 18 November 2011

The Case of the Hung Visual Studio Installer

(with apologies to Mark Russinovich :-) )

I got my shiny new work laptop on Tuesday this week, a HP EliteBook 8560P. Mmm, shiny.

So a portion of the remainder of my week has been spent on installing things like SQL Server and other development tools on it. Until I got to Visual Studio 2010, for which the installer hung at the end of the first screen (the one where it installs Setup components before you get to choose which bits of VS you actually want to install).

A few details. I'm running Windows 7 Enterprise, and I was installing Visual Studio 2010 Ultimate. I was using Virtual CloneDrive to mount an ISO image of the Visual Studio DVD from a USB hard drive. All things I've done before without any issues.

Thought 1: My ISO image has got subtly corrupted somehow. I downloaded from MSDN a new ISO image of Visual Studio. No joy.

Thought 2: There's a problem with running the installer off a mounted ISO. Despite being sure I'd successfully run off a mounted ISO before, I burned a DVD and ran the installer from there. No joy.

At this point I tweeted that I was struggling:
I was grousing more than expecting anyone to offer advice, but I received these tweets back:
Fair enough, I'll give that a go:

Thought 3: It is working, I'm just not giving it long enough to work. I ran the installer for at least 8 hours overnight Wednesday. No joy.

At this point I was Googling pretty hard for issues relating to the Visual Studio hanging, but no one seemed to have had a problem at the same stage as me. It did lead to me trying

Thought 4: A missing Registry key
I added the key. No joy.
Thought 5: The installer was trying to write temporary files to the external USB drive. I copied the ISO onto the hard drive, disconnected the external USB drive and re-ran the installer. No joy.

Desperation was setting in at this point, and I began to wonder if the problem was my install order.

Thought 6: Because I've installed SQL Server (and SQL Express), something in SQL Server is interfering with the install. I uninstalled both instances of SQL Server 2008 and the shared components. No joy.

Here comes the science bit...
I'd already been running SysInternals' Process Explorer to try and see what was going on with the installer process but it didn't really show me enough detail. However I notioced from a discussion on the Microsoft forum someone else using Process Monitor, so I fired that up instead, and filtered it so I was just looking at setup.exe. This is what I saw:

My first thought here was: why is setup.exe trying to write files to, closely followed by: have I done this right or is Process Monitor somehow screwing up these results? And suddenly, in one of my occasional flashes of intuition, it clicked.

The Answer
I have a drive mapped to \\\tools, and the drive that I have mapped is the I: drive. 'Cos, y'know, Internals begins with I. Turns out that the Visual Studio installer maps a folder in your %TEMP% folder to I: too and then uses it for decompressing some of the CAB files that the installer uses. Since I already had an I: drive, the installer was trying to use it but failing as I (obviously) don't have write privileges to the SysInternals folder, and the whole thing ended up in an infinite loop. I unmapped my I: drive from the SysInternals folder, re-ran the installer and everything installed successfully.
Now, clearly, the set of people who a) have an I: drive mapped but b) don't have write access to it and c) need to install Visual Studio, is going to be pretty small, but at the same time I can't help feeling the installer should have handled this better. In the end it was a simple workaround for me to resolve it, but it took me too long to discover the problem. Logged on Connect at

Tuesday, 8 November 2011

World Clocks with jClock and TimeZoneInfo

Everyone else seems to be writing about the clocks changing this week, I don't see why I should miss out...

Last year while I was working on our group intranet project, I wrote a web part for diplaying times around the world corresponding to some of our major offices. It uses the jClock jQuery plugin so it does actually tick every second instead of being static (and in a future release I'm going to change this so it doesn't show the seconds and only ticks every minute instead). The list of locations is driven by an XML file so we can dynamically add more if we open offices in other time zones.

jClock by default shows you your local time, or you can give it an offset (in decimal) from GMT/UTC if you want to display the time from a different timezone. So the XML file that we went into production with last year was along the lines of;

The serverside code in the web part then uses a HtmlTextWriter to generate a set of DIVs and a block of JavaScript that sets up jClock.

<script type="text/javascript">
    $(document).ready(function ()
        $('#jclockLondon').jclock({ utc: true, utc_offset: 0 });
        $('#jclockStockholm').jclock({ utc: true, utc_offset: 1 });

<div style="text-align: center;">
        <span>Local time:</span>
        <span id="jclock"></span>
    <div style='background-color: #F0F0F0; width: 100%;'>
        <span id='jclockLondon'></span>
        <span id='jclockStockholm'></span>
The  two generated strings are put into a Pair and then cached as one object to cut down some of the work for the server. And all this was fine, until the clocks changed in the spring. I worked out the new offsets and updated the XML file on the server, so then we had;

When the clocks changed again last week, I realised that this was going to be unsustainable and needed reworking. My first thought was to add a set of dates to the XML that denoted when to switch between winter and summer times. I coded this up, tested it, and checked it in, thinking I was done. Until it was pointed out to me that not everyone changes their clocks on the same date. 

With a steer from Gustaf, I looked into the System.TimeZoneInfo class. Now I wish I'd looked at this last year...

To get an instance of the TimeZoneInfo class, you call the static method FindSystemTimeZoneById and pass it the string Id of the timezone you want e.g. 'GMT Standard Time'. You can see all the timezones that your system supports by calling GetSystemTimeZones, which returns a ReadOnlyCollection of all the timezones Windows knows about. Each timezone has an id but also a DisplayName e.g. ' - it's the DisplayName that you see if you go into the Control Panel to change your system's timezone:

The id is constant across all installations of Windows, however the Displayname is localised - this was an important point for me as our intranet runs on servers in Sweden. For our World Clocks web part, the key function of TimeZoneInfo is GetUTCOffset. This takes a DateTime parameter which allows you to calculate the UTC offset for any given timezone on any given date. The key point is that this automatically factors in daylight savings times e.g. British Summer Time. I'd expected British Summer Time (or equally Central European Summer Time) to be listed as separate timezones, but they aren't, the timezone knows when it should apply changes for daylight savings e.g.

TimeZoneInfo info = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
Console.WriteLine(string.Format("Id: {0} - DisplayName: {1}",
Console.WriteLine(string.Format("Summer offset is {0}"
info.GetUtcOffset(new DateTime(2011,5,7))));
Console.WriteLine(string.Format("Winter offset is {0}"
info.GetUtcOffset(new DateTime(2011,11,7))));


One of my colleagues asked what will happen if the rules for a given timezone change e.g. suppose the UK changes the dates on which the clocks change. The answer is this is now Microsoft's problem instead of mine, all the timezone information is held in the Registry and if any timezone changes, Microsoft will release a Windows Update that contains the new information.

So I've got rid of an annoying manual job in changing the XML twice a year, and the XML itself is much simpler because now for each location all it needs is a name, and a timezone id. Simples.

Friday, 10 June 2011

Guathon 2011

Monday this week saw this years Guathon in London, a day of technical presentations from St Scott of Guthrie, ably assisted this year by Steve Sanderson. The event is free and held in a cinema - now I know how big I want my next monitor to be :-) Unfortunately, due to Microsoft's lack of organisation in changing the venue at the last minute, there were lots of empty seats and many more developers could have attended. This year Scott did the first and last sessions, with Steve covering the late-morning/early-afternoon shifts.

Build An App Using ASP.NET MVC 3, EF Code First, NuGet, and IIS
The first session (which due to National Express East Anglia's incompetence I missed the start of) was Scott covering some of the features of MVC3/Razor and Code-First Entity Framework. This was probably the session I got the most out of all day, as I haven't done any MVC/EF in anger yet there was a lot of value here for me. Key points I took away were:
Razor syntax
@ - starts a code block
@:  - is the prefix for a string literal e.g. if you want to output some HTML inside a code block
There is detection for the @ symbol inside an email address that means it automatically renders a mailto: link
@@ - acts as an escape character
@helper - one of the biggest things for me, I've never seen this before. @helper allows you to write a helper method that acts like a method but with Razor syntax so you can call the helper to display a canned piece of HTML. Helpers can be declared in-line or in a partial class within the App_Code folder. Scott also mentioned that David Ebbo (@davidebbo) has a project on his website that allows you to write helpers that are compiled into an assembly. It's actually now on CodePlex at
@model -By default the Model variable in a page is of the dynamic type, which means at design-time you don't get (much) Intellisense from it, however an @model declaration at the top of the page allows you to specify the exact type of Model, and you then get proper Intellisense support. If you create the View as a strongly-typed view and select the concrete type the View will support, it puts an @model declaration in for you.
_ViewStart.cshtml - Allows you to setup defaults for a set of views, including setting the _Layout.cshtml page. Someone asked whether you can have multiple _ViewStarts, Scott didn't know but was surprised when someone else said that you can. Gunnar Peipman's blog makes this clear - a _ViewStart is scoped to the folder that it is in.
_Layout.cshtml - The Razor equivalent of an ASP.NET Master page.

Scott also showed off a couple of tools:
Modernizr.js - allows you to detect which HTML5 and CSS3 features are supported on the browser instead of detecting these from the User-Agent string. Scott also showed off some HTML5 features in his demos, to which somebody asked if you could use those outside Razor. Scott's reply? "Yes, you can open your project and start typing the HTML5 tags" :-)
Glimpse - "FireBug for your server" is the best description of this tool. It shows you on the client what is happening on your server, how your server is configured. And I confess I'm pleased to see this is currently available for ASP.NET only, I'd assumed it was something other frameworks had had for a while but it seems not.

Dynamic Web UIs with Knockout.js
Steve's first session covered Knockout.js, an MVVM framework that works with any JSON feed. I think I may have misunderstood the principle behind this, it seemed to me to be largely another jQuery templating framework, although looking on the website it says that you can use your choice of templating engine. Talking to others in the evening though, there seem to be other concerns around Knockout - lack of testability and accessibility were the principal ones, and no degradation support means for me I'm unlikely to use Knockout. Plus I'm primarily a server-side guy - I can do some jQuery but right now I don't have the bandwidth to learn another JavaScript framework.

C#5 and Asynchronous Web Applications
After lunch Steve was on again, demoing some of the asynchronous bits that are coming in C#5. Steve talked about polling, long polling and sockets. The difference between these is as follows (I've probably got these wrong, if I have someone please tell me so I don't look a complete Muppet):
  • polling - call a service at a regular interval e.g. every second, the service returns any changes made since the last call.
  • long polling - call a service, the call doesn't return until the service has some data to return to the client, however long this takes.
  • sockets - opens a channel between the caller and a service and the service then returns data to the client whenever it has any, keeping the channel open.
Of these sockets is the best, however there is currently limited support for it on browsers so we won't see this go mainstream for a little while yet. 

Cloud Development
The last session of the day saw Scott back on the podium talking about developing for the cloud and Windows Azure. Scott has recently taken on management of the Azure team, although this was badly publicised as it sounded like Scott had moved away from ASP.NET and all the other things he was managing - this is not so, he's still in charge of ASP.NET and everything else, the Azure stuff is in addition to, not instead of. Scott talked about and showed off a lot of the infrastructure behind Azure, including fun facts like:
  • the ratio of servers to staff in the data centres is 15 000:1
  • the centres are constructed from containers
  • the newer containers they are deploying don't have roofs which saves a lot of energy on cooling
  • for every watt of energy that powers a server, they only use an additional 0.1 of a watt on ancillary usage such as heating/cooling etc
This gives you a much lower TCO when you use services in the cloud, however Scott came out with the quote of the day when talking about this:
"Developers don't care about money, we just care about developing cool stuff."
Employers, take note...

Scott demo'ed developing an ASP.NET application to be hosted in the cloud and showed the steps necessary to set this up. I was interested to hear that there is/will be a PowerShell commandlet for deploying solutions to your Azure setup.

Scott showed off some forthcoming technology on Azure, a Queuing service allowing you to de-couple parts of your business processes, which was interesting and made me wonder whether Microsoft might be thinking of putting some of the BizTalk infrastructure in the cloud. This would be a big win, I think, in terms of making BizTalk a more accessible technology and getting more take-up - we looked at BizTalk for a project a couple of years ago but the costs for setting up BizTalk on-site are currently prohibitive.

Scott presented a mini-case study on EasyJet - they host their applications in the cloud and then connect to them in airports using local WiFi, which saves them money on having to setup infrastructure in every airport they operate in.

Scott touched on the Azure AppFabric caching service, which I'm interested to know more about - I'm still fuzzy on the benefits. The throughput rate for the caching service is 4Tb/s - not too shabby. Scott also mentioned, almost, as my old German teacher would say, en passant, that Microsoft will shortly be rolling out a Content Delivery Network service on the Azure infrastructure, which is something I find really exciting. But maybe I'm just sad that way...

Thanks to Scott and Steve for presenting, Phil and Dave for organising it all, and Paul, Nathan, Johan and Dan for the conversation over dinner at TGIs!