.Net has built in compiling and code generation via the CodeDom namespace. The code generater takes a CodeDom object (a language inspecific program) and writes sourcecode for it in either vb or c# depending on which object set you use.

I'm interested in translating some c# code to vb using the codedom.

The c# to vb translator I wrote uses this code to translate:

VB Code:
  1. Dim cs As New Microsoft.CSharp.CSharpCodeProvider
  2.         Dim csParser As CodeDom.Compiler.ICodeParser = cs.CreateParser
  3.         [B]Dim DOM As CodeDom.CodeCompileUnit = csParser.Parse(New IO.StringReader(tC.Text))[/B]
  4.  
  5.         Dim vb As New Microsoft.VisualBasic.VBCodeProvider
  6.         Dim vbGenerator As CodeDom.Compiler.ICodeGenerator = vb.CreateGenerator()
  7.         Dim Output As System.Text.StringBuilder()
  8.         Dim Dest As New IO.StringWriter(Output)
  9.         vbGenerator.GenerateCodeFromCompileUnit(DOM, Dest, New CodeDom.Compiler.CodeGeneratorOptions)
  10.         tV.Text = Output.ToString

The bolded line is where execution stops and I get a Null Reference Exception. What gives?

The source of the C# code is a textbox names 'tc' and the vb output should go to 'tv'.

Let me know if this can be done... it should have no problems.