Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Running .NET 1.1 Applications on .NET 2.0

5.00/5 (1 vote)
13 Apr 2010CPOL2 min read 1  
Running .NET 1.1 Applications on .NET 2.0

One of the applications I developed is a .NET 1.1 Windows Forms application used by more than 5000 users and is critical for the business.

Being a complex and critical application, porting it to the 2.0 runtime just because it was not an option, it would mean installing the new runtime and framework on the stable environment of the workstations (Windows XP) and fully test the application. That was not an option.

As time went by, a developer received a brand new laptop with Windows Vista. Since he only needed .NET 2.0 for his developments, he never installed .NET 1.1.

Another developer on my team had already tried to port the application to .NET 2.0 and run into some issues:

  • The main component of this application is the Web Browser Control. This control derives from AxHost, which changed going from 1.1 to 2.0 and needed major changes to compile for the 2.0 framework.
  • Another change was that mixing synchronous and asynchronous calls is not allowed in the 2.0 framework and we had, at least, one of those in our use of HttpWebRequest/HttpWebResponse.

The .NET 2.0 runtime and frameworks were developed to be highly compatible with applications written and compiled to the 1.1 runtime and frameworks. In fact, some of the changes were just applying the ObsoleteAttribute set to throw a compiler error when used, which doesn't prevent its use by already compiled assemblies. This was the case of the WebBrowserControl/AxHost and just using the assembly compiled for .NET 1.1 would probably run fine. And it did.

The synchronous/asynchronous was also very easy to fix. All it took was changing this:

C#
request.GetRequestStream()

into this:

C#
request.EndGetRequestStream(response.BeginGetRequestStream(null, null))

And it all worked as if it was running on .NET 1.1.

But that’s not the end of it. Later came a requirement to use, in one of the web pages that ran in the web browser control, an ActiveX component developed in .NET 2.0.

But that time, the 2.0 runtime and framework were already installed on the workstations.

How would we force the application to run in the 2.0 runtime if the 1.1 runtime was still there?

It was as simple as adding this to the configuration file (App.config):

ASP.NET
<configuration>
  <startup>
    <requiredRuntime version="v2.0.50727" safemode="true"/>
  </startup>
</configuration>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)