How to Convert a VB.Net Project to C#



How to Convert a VB.Net Project to C#


There are four steps to converting a Visual Basic.Net project to C#:


1) Check for potential conversion problems and correct

2) Convert your VB.Net project to C# and review conversion notes

3) Fix C# compiler errors (by changing VB.Net code if possible) and reconvert

4) Fix any runtime issues



Check for Potential Conversion Problems


The first step in a conversion is to check for potential conversion problems.  From the main screen, pick "Convert a VB.Net Project to C#".  Before the conversion actually takes place, your project will be automatically checked for possible conversion issues.




Next, you will be prompted to pick a VB.Net project to convert. Choose your project and press "Open".




Your project will be first be checked for potential problems before converting and you will be shown a screen similar to the one below: 




Press "Review Potential Problems" to see the potential conversion problems (recommended), or you can click "Proceed With Conversion" to immediately start the conversion.


It is highly recommended to fix all high severity potential problems before attempting a conversion.  Medium severity problems are often successfully handled during conversion, but high severity problems will almost always result in C# compiler errors and can interfere with the automatic C# compiler error fixing feature of the converter.



When you are done fixing potential conversion problems and are ready to convert, repeat the above steps but press "Proceed with Conversion".



Convert Project to C# and Review Conversion Notes


After proceeding with the conversion, you will see a conversion summary screen similar to the one below, which will list the statistics of the conversion, such as number of lines of code, and any conversion notes and C# compiler errors encountered. 



Press "View Conversion Results" to see side by side VB.Net and C# code listings, and to review any potential problems, conversion notes, and compiler errors encountered:




You can double-click a conversion note, potential problem, or compiler error to see its corresponding VB.Net and C# code, or press the previous and next issue buttons to navigate through the issues encountered.  Pay particular attention to any high severity conversion notes issued and try to correct the issues in the VB.Net code if possible and reconvert.




Fix C# compiler errors (by changing VB.Net code if possible) and reconvert


The converter fixes many C# compiler errors for you, but there may be some the converter can't automatically fix.  If your project encounters C# compiler errors, you should attempt to change the source VB.Net code if possible to avoid the errors and convert again.


Fixing C# errors manually may expose other C# compiler errors the converter hasn't had a chance to identify and correct, since compiler errors tend to be produced in waves starting with the most severe.  These additional errors would normally be corrected by the converter in its normal processing, so you can save a huge amount of work by changing the VB.Net code and converting again rather than changing the C# code directly.




Fix Runtime Problems


Once your project compiles successfully, the runtime behavior should be thoroughly tested.


One potential issue to check is relative path names.  For example, if your initial VB.Net code was:


Dim sr As New System.IO.StreamReader("..\test.txt")


Your converted C# code is now in a different directory and the path may be invalid or the file not found at the new relative location. You should change the code to use a different relative path name or explicitly point to the appropriate directory.




Copyright 2012, VBConversions