Click here to Skip to main content
15,887,683 members
Articles / Programming Languages / C#

Running .NET 1.1 Applications on .NET 2.0

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
13 Apr 2010CPOL2 min read 13.9K   3   4
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)


Written By
Software Developer (Senior) Paulo Morgado
Portugal Portugal

Comments and Discussions

 
QuestionDoubt about changing version Pin
chisclas4-Apr-11 20:56
chisclas4-Apr-11 20:56 
AnswerRe: Doubt about changing version Pin
Paulo Morgado5-Apr-11 14:13
professionalPaulo Morgado5-Apr-11 14:13 
GeneralRe: Doubt about changing version Pin
chisclas5-Apr-11 20:30
chisclas5-Apr-11 20:30 
GeneralRe: Doubt about changing version Pin
Paulo Morgado5-Apr-11 23:23
professionalPaulo Morgado5-Apr-11 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.