Q. I'm a C# developer being forced to code in VB.NET...Any C# to VB conversion tools?

Asked by Patrick Crawford. Answered by the Wonk on January 16, 2003


As far as being a C# developer forced to code in VB.NET, I donít think thatís necessarily all bad. The technical team lead for the .NET CLR, whoís previous job was as an MIT professor for 20 years, actually prefers VB.NET as his managed language of choice. I donít fault him entirely. VB.NET has some real advantages over C#, including line-by-line compilation, case correction (instead of case sensitivity), optional loose binding w/o writing Reflection code, a simpler event handling model, the filtering event handling scheme and various IDE enhancements all make VB.NET a pleasant language if you can get over the different, more verbose, syntax. Plus, when compared to VB6, VB.NET provides a cornucopia of language enhancements that make it useable by ďrealĒ object-oriented programmers. Implementation inheritance alone is worth the upgrade from VB6 to VB.NET as far as Iím concerned.


On the other hand, I still havenít switched, so I know what youíre after: some way to write code in C# and convert it after the fact to meet project/management/department/satanic requirements. I wouldnít recommend that, frankly. While VB.NET and C# are roughly on parity feature-wise, the quality of the code you write directly in VB.NET is going to be much better than the quality of code that comes out of a C# to VB.NET conversion utility. VB.NET has a different culture (which you may or may not want to emulate) as well as some different conventions (which you absolutely should emulate) that canít be duplicated by any conversion utility that Iím aware of.


However, if you absolutely must convert C# code to VB.NET code, I know of a few tools that provide this service:



None of these tools is going to be perfect, unfortunately. My ideal tool would actually compile the C# code and translate it into a .NET CodeDOM object model, letting me spit it out any .NET language with a code provider. Please let me know if you build such a tool.

How I Discovered This

My ideas about whether itís better to convert from one language to another come from experience. If a human has to read or maintain a hunk of source code, itís always better than a human generate it in the first place, otherwise important language and culture-specifics are going to be missed or just plain wrong.


The list of conversion tools came from following a link that Paul sent me himself and paying attention to the community that expresses itself via mailing lists and blogs. BabbelFisken was mentioned on Sean 'Early' Campbell & Scott 'Adopter' Swigart's Radio Weblog, for example.


My need for a C# to CodeDOM conversion tool comes not from my need to write C# and produce VB.NET (although Justin Gehtland is performing this service for me in porting my C# WinForms book to VB.NET), but my need to build code generation tools (like CollectionGen and XsdClassesGen). Right now, I need per-language code generation templates, which are impossible to keep in parity. If I had a single C# template that I used to generate the code, but passed it through a C# to CodeDOM compiler, I could output C# or VB.NET or any other language with a .NET code provider.


I have feedback on this Ask The Wonk answer