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!

Thursday, 17 February 2011

Making a Hybrid Web Application Project Type

Like so many of my blog entries, I've been meaning to write this one for weeks. Ever since Scott Hanselman wrote Integrating ASP.NET MVC 3 into existing upgraded ASP.NET 4 Web Forms applications, in fact. Scott just wrote an updated post on using NuGet to bring the MVC bits into a WebForms application, which is a muc easier way to do it. But to me, Scott's still missing the final piece of the puzzle which is: do this once, create it a project type from it, and forget about it.

So, creating a hybrid project type. First of all, go do Scott's NuGet stuff and create your hybrid application. Oh, and add any of your other favourite references - NHibernate, CastleWindsor, whatever. It's OK, I'll wait.
Done that. Good.
Now click File|Export Template... and open the Export Template Wizard. Check the 'Project Template' radio button so we export the hybrid project as a template. Click Next.
On the second screen, enter a suitable name for the project type and description, and choose an icon if you want.

Click Finish and you're done!

Sunday, 30 January 2011

What's A DDD9?

Some of my (non-geek) colleagues who follow me on Twitter have asked me recently: what's a DDD9? The answer: for the UK .net community, it's the major event of the year. Held annually at Microsoft's offices in Reading, it is a free one-day conference run totally by the community. The DDD stands for Developer Developer Developer, from Steve Ballmer's chant of several years ago ( *. Microsoft employees are welcome to attend, but they aren't allowed to speak. It is only advertised through word-of-mouth and Twitter: this year it sold out 350 spaces in 12 minutes, the waiting list for spaces was full after another 30 minutes. You may find this slightly more notable as DDD is held on a Saturday, which ensures that the people who are there are the kind of passionate people who are prepared to give up a large part (or in many cases the entirety) of their weekend to attend. The programme is completely voted for by the attendees, this year there was again a great mix of technical and technique sessions. The sessions I saw this year were:

.net Collections Deep Dive - Gary Short
Actually I wanted to see all four talks in the first session, but I picked Gary's as I don't think I've ever seen him talk before. This was a session going through many of the Collection classes available in .net, how they work internally and in what circumstances each one offers better performance. It included such gems as the fact that in the multithreaded collections if you call the Count property it is not guaranteed to be accurate unless you can be sure all threads have exited. In which case it wouldn't be, y'know, multithreaded. The top tip I took away was that if you know how many elements you are going to put in a collection, to set the Capacity in the initialiser:
List myListOfTenElements = new List(10);

CQRS, Fad or Future - Ian Cooper
OK, so I, um, didn't actually see this session, I got chattinjg to people in the speakers lounge. The presence of chocolate and raspberry cheesecake brownies (made by me) was a total coincidence. This was still quite useful as I was able to talk to Dave Sussman about a CSS issue I'd been having and get some advice. However I look forward to seeing Ian's slides and maybe catching this talk at a user group sometime.

A Primer on RavenDB - Rob Ashton
One of the sessions I really wanted to see as I'm interested in playing with RavenDB and I can see cases in WSP where it could be a very good technical fit. Rob is quite opinionated, especially on how MongoDB and RavenDB differ. Rob recommends getting the unstable version of RavenDB to play with so you can see the features, although I think at least initially I'll be using the stable build until I've found my feet with it. One of the things I'm most impressed with is the fact that for unit testing purposes, you can run RavenDB completely in memory with no impact to disk.

Is Your Code SOLID - Nathan Gloyn
This talk walked through the SOLID principles of software engineering.Nathan began with a pretty ropey bit of code, and then talked through each principle before demonstrating how the code changed after the application of the principle. A really interesting session for me, SOLID is something I need to think about more as I write software.

CSS Is Code - Helen Emerson
Helen's theme was that CSS code is as important as application source code, but that the rules and principles we apply to source code aren't often applied to CSS. Probably not the right session for me given that I'm a total numpty where CSS is concerned, although it was useful to see that in Helen's demos there were things that chimed with some of the CSS we used on the Intranet last year.

A Beginner's Guide to Continuous Integration - Paul Stack
A great session to round off the day from Paul Stack, talking about how to use CI to reduce the time it takes to release your software. Like RavenDB, CI is something I definitely want to look into, in fact in that respect it was a shame it was a Saturday as I was fired up enough that I wanted to go straight into the office and set up a CI server. The only real negative in this session for me was that there was little discussion of how to set up CI with TFS, although Paul tells me this is straightforward.

The Social Network
There's much more to DDD than just a technical conference - for many if not all of the delegates it is as much a social event as a learning opportunity. It's a chance to catch up with old friends, make new ones, or just an opportunity to put faces to Twitter handles - I've been chatting with Nathan and Paul on Twitter for months but Saturday was the first time I'd met them. And the socialising continues into the evening - there is a Geek Dinner after the conference, at which 40 of us take over most of Pizza Express to eat, drink and chat.
We had an interesting conversation at our end of the table about the nature of developers and DDD and why it seems to work for us but no-one else. There simply doesn't seem to be any other profession that does events like this - even inside IT, there's no equivalent event for IT Pros.

* I did discover through the power of Google an alternative DDD9 conference - Death, Dying and Disposal. Which doesn't sound anything like as much fun.