Sunday 26 May 2013

Web App Upgrade From .NET 3.5 to .NET 4.5

We've recently gone about upgrading our web application from .NET 3.5 to .NET 4.5 and as you could probably guess, it didn't quite go as smoothly as one would hope.

As we go through this process I'm going to blog about the difficulties and what we did to overcome them.

So, here we go...

System.Web.UI.HtmlControls.HtmlIframe


This is a whole new type in .NET 4.5 and oddly, it can cause a few problems.

Take this line of code for example:

<iframe src="about:blank" id="myFrame" runat="server" />

If you wanted to refer to this control in C# code, in 3.5 you'd write something like this (preferably in a designer.cs file):

HtmlGenericControl myFrame;

In .NET 4 however, an iframe is no longer an HtmlGenericControl, it's an HtmlIframe which does not inherit from HtmlGenericControl. This means you need to change the above line of code to something that looks like:

HtmlIframe myFrame;

Creating this HtmlIframe class makes sense and means that iframes have their own object, much like the HtmlTable class but, it does seem odd that it does't inherit from HtmlGenericControl. Unfortunately, this design decision has knock on effects for upgrades. Any iframe which has been defined as an HtmlGenericControl now needs to be changed to an HtmlIframe. To make matters worse, if you've manually defined these controls and they're not wired up via an auto-generated designer file, then the problem won't be picked up at compile time. You'll need to actually run the application and wait for it to fall over to find the problem.

The joys of upgrades eh?