Monday, May 7, 2012

Migrate VB.NET code to C#


There are various reasons to migrate the code to C#, few of them are listed below:

  • C# is an ECMA standards compliant language with a formal definition and a corresponding abundance of third party and open source tools. VB.NET is at Microsoft’s mercy to do whatever they want with it – and they do. VB.NET makes it easy for VB programmer to move to .NET.
  • C# code is faster as generated MSIL from C# and VB.NET is not same always
  • Terseness and readability of code. C# follows the C, C++, Java syntax tradition, while VB is more verbose.
  • IDE Responsiveness – It is difficult to work with a large VB.Net project in Visual Studio
  • Improved Code Quality – C# catches many errors allowed in VB.Net, such as variable use before initialization and dead code. It also doesn’t allow undeclared variables, untyped variables, and untyped methods that are allowed in VB.Net.

We will be using an open source tool SharpDevelop developed by IC# (http://www.icsharpcode.net/). This tool is an open source IDE to develop .NET applications similar to Visual Studio and also gives the ability to convert your entire project from VB.NET to C#. We did a POC to convert eService application to C# and its results are very promising. The only compiler issues I found was the implicit type casting issues which C# does not allow. The steps to convert are listed below:


Note: A web site project first need to be converted to a web application project before you can convert the code to C#. You should also upgrade .NET framework before migrating the code to C#