.Net 1.1 to 2.0 conversion mistakes

Over the past week i have been working on a conversion (.NET 1.1 to 2.0) project. It started as fun and turned out to be little tedious !!!

First of all, its a big solution with around 25 projects (both C# and VB.NET) and quite a good amount of ASP code, doing various tasks…

The first part of the project turned out to be simple…

Goal : Make this solution run under .NET 2.0 framework and upgrade to WES3.0.

We have decided to go with Web Application Project rather than Web Site Project.

  • Installed .NET 2.0 and the updates to Web Application Project.
  • Opened the solution using Visual Studio 2005 (this did the conversion which was very simple).
  • Converted the web project to New Web Application Project (Got all the nice! designer and partial classes).
  • Update the WSE2.0 references with WSE3.0 references.
  • Enabled “Security” and update the references, etc…

That worked out very well to that point and we have to turn on the “Option Strict” and “Option Explicit” turned on (I know its scary that we have been working on these conditions :) ).

Second Part: Turn on Option Strict and Option Explict and get the error and warning count to “ZERO”.

We ended up with few thousands of error and warning messages. In an effort to quickly resolve these issues, we have made some silly mistakes that any one of us could have avoided with literally few min of thinking..

Here are some of them:

  • “DirectCast”: This truned out to be a fatal error as the run time type must be same of the target type for this to work. Started seeing exception messages.

Revisited all the DirectCast operations and used DirectCast and CType carefully.

Some reference for DirectCast vs CType: Directly taken from www.dotnet247.com message board

“Both keywords take an expression to be converted as the first argument, and the type to convert it to as the second argument. Both conversions fail if there is no conversion defined between the data type of the expression and the data type specified as the second argument.
The difference between the two keywords is that CType succeeds as long as there is a valid conversion defined between the expression and the type, whereas DirectCast requires the run-time type of an object variable to be the same as the specified type. If the specified type and the run-time type of the expression are the same, however, the run-time performance of DirectCast is better than that of CType.

DirectCast is special in that conversions from type Object to any other type are performed as a direct cast down the hierarchy – all of the special conversion behaviors from Object are ignored.  DirectCast requires the run-time type of an object variable to be the same as the specified type. If the specified type and the run-time type of the expression are the same, however, the run-time performance of DirectCast is better than that of CType.”

  • String.Emtpy: We have some code that is simply covied over to .NET from legacy VB and ASP. And most of the places our variables are not instantiated. Some hasty decision to assign “String.Emtpy” to all string references back fired on us.

         Our code looks for conditions like “if str is nothing” which is not a good enough condition as the “str” could now be “String.Empty”

Revisited “String.Empty” and used “nothing” as appropriate

  • Rename Variables: most of our class level variable names in our aspx and ascx file start with “_” and we are getting CLS complient warning message. Our simple solution was to put “m” as prefix using the VS 2005’s rename functionality. This worked very well except it did not change the instances where these variable appeared in .ASCX and .ASPX file.

Have to use different reg exp to fix the new issues we have introduced.

We, at least i, should have thought of these issues for few minutes before going on this adventure!!! Any how we are at “0” errors and “0” warning messages with only “1” known minor bug…

Leave a Reply

Your email address will not be published. Required fields are marked *