20 Oct 2012

.NET 4.0 on Windows XP SP2: yes you can

QUICK ANSWER: You can install .NET 4.0 on Windows XP SP2 machines and run your winforms applications with no apparent problems. Be aware that it is not a supported scenario but if you don’t have any other option you can definitely try it.

Why I’m moving to .NET 4.0

My main product is a Winforms application that runs on .NET 2.0. I’ve resisted the temptation to upgrade to newer framework versions because it’s not easy to ask or convince customers to install additional libraries even if they come from Windows Update- Also, I’ve personally seen many customers still running my app on Windows XP SP2 machines which .NET 4.0 doesn’t support, at least officially.

This app also uses SQL Server 2005 Express as its backend.

Soon, some of my bigger customers will need to upgrade to SQL Server Standard. The easy path would be to install SQL Server 2005 Standard but I don’t think that it’s even possible now. SQL Server 2005 is three major versions behind.

So for those customers is going to be SQL Server 2012. This shouldn’t be a problem as the code should work without changes just fine right?

And it does indeed. Unfortunately, my application uses SMO to create and update the database, to backup and restore data among other fancy things and that didn’t work.

So the first error when I launch my app against SQL Server 2012 is:


 This SQL Server version (11.0) is not supported. (Microsoft.SqlServer.ConnectionInfo)

Program Location:

   at Microsoft.SqlServer.Management.Common.ConnectionManager.CheckServerVersion(ServerVersion version)
   at Microsoft.SqlServer.Management.Common.ConnectionManager.InternalConnect(WindowsIdentity impersonatedIdentity)
   at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()

Makes sense, as I’m using the SQL Server 2005 SMO assemblies. I just need to change those assemblies with the 2012 (v. 11) assemblies and I’m ready to go. But that doesn’t work because the new assemblies use .NET 4.0.

So, finally I have a good justification to move my application from .NET 2.0 to .NET 4.0. I updated all the projects to target .NET4 and run it on my development machine. It crashed with this exception because my app is using third party libraries targeting .NET 2.0.

Mixed mode assembly is built against version 'v2.0.50727' of the runtime
and cannot be loaded in the 4.0 runtime without additional configuration information.

To solve this I had to add this to my app config file.


    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>

{% highlight %}

## Installing .NET 4.0 on Windows XP SP2

After installing a Windows XP SP2 virtual machine, I grabbed the
[.NET 4.0 web installer](http://www.microsoft.com/en-us/download/details.aspx?id=17851) and fire it up.

It complained about [Windows Installer 3.1](http://www.microsoft.com/en-us/download/details.aspx?id=25)
not being present. No problem, I installed it and tried again.
This time it complained about [Windows Image component](http://www.microsoft.com/en-us/download/details.aspx?id=32)
not being present on the system. I installed that and tried once more:

  Installing Client Profile...
  Installing .NET 4 Extended...
  Installation complete!

  No errors.

Finally, the moment of truth. I launched my application and... everything run just fine. I'm still testing it but
I'm not experiencing any problems so far.

So, yes, you can install .NET 4 on Windows XP SP2 and run .NET4 applications. At least Winforms applications.
Perhaps WPF or ASP.NET applications crash as soon as you run it but for now, my winforms app is doing fine.