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#
3) Review conversion notes and fix C# compiler errors
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 "View Problems" to see the potential problems (similar to below). You can double click to see the details of a potential problem or print detailed reports from the Reports menu.
It is highly recommended to fix all Critical and High severity potential problems before attempting a conversion. Most Medium severity potential problems are handled successfully by the converter, but can sometimes be a source of problems. If correcting Medium severity errors is too time consuming, you can attempt a conversion and see if any of the potential issues actually cause problems.

When you are done fixing potential conversion problems and are ready to convert, repeat the above steps but press "Convert Anyway" when potential problems are displayed.
Convert Project to C#
When you are done fixing potential conversion problems, you can then convert your VB.Net project to C#. From the main screen, choose "Convert a VB.Net Project to C#".

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 "Convert Anyway" to convert to C#. A screen will be shown which lists a summary of the conversion statistics. Press "View Conversion Results" to see the details of the conversion.

From the detailed conversion results screen, you can view the results by file, view potential problems, conversion notes, and C# compiler errors.

Double clicking on a file will show the file conversion details and a side by side code listing.

Conversion notes can also be reviewed. These are interesting things which happened to your code during the conversion to C#. Pay particular attention to high severity issues as they can frequently cause C# compiler errors. Generally, you should fix high severity conversion notes in your VB.Net project (not the C# project) and reconvert.

You can double-clicking a conversion note, potential problem or compiler error to see its details.

Press "View Problems" to see the potential problems (similar to below). You can double click to see the details of a potential problem or print
For large projects, it can take a long time to convert and there may be intermittent pauses. Let it run to completion. For converting large projects, it should be run on a relatively powerful computer.
Once the project is done converting, the number of compiler errors and conversion notes will be displayed, similar to below:
Review Conversion Notes and Fix C# Compiler Errors
After your project is converted to C#, you should:
1) Review conversion notes. Pay particular attention to high severity issues and fix in your VB.Net project and reconvert.
2) Fix C# compiler errors. It is counter-intuitive but extremely important to try to fix any C# compiler errors by making changes in your VB.Net code and reconverting.
|
Note - Fixing C# compiler by making necessary changes in your VB.Net program (not the converted C# program) is very important. The converter achieves its high accuracy by successive C# compiles and automatic error fixing of the converted code. A severe C# compiler error can stop this process prematurely and prevent the automatic fixing of compiler errors in totally unrelated areas of code. It is highly recommended that you hold off as long as possible from changing the generated C# code. |
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 (initially in the CS directory under your VB.Net project 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 © 2009, VBConversions