Try If TextBox1.Text.Trim <> "" Then Dim VBP As New VBCodeProvider Dim CVB As System.CodeDom.Compiler.ICodeCompiler CVB = VBP.CreateCompiler Dim PM As New System.CodeDom.Compiler.CompilerParameters PM.GenerateInMemory = True ' PM.GenerateExecutable = True PM.OutputAssembly = "Generated.dll" PM.MainClass = "ClassMain" PM.IncludeDebugInformation = True Dim ASM As System.Reflection.Assembly For Each ASM In AppDomain.CurrentDomain.GetAssemblies() PM.ReferencedAssemblies.Add(ASM.Location) Next 'Get compilation results Dim Results As System.CodeDom.Compiler.CompilerResults Results = CVB.CompileAssemblyFromSource(PM, TextBox1.Text) 'Show possible compilation errors Dim Err As System.CodeDom.Compiler.CompilerError For Each err In Results.Errors ListBox1.Items.Add("Error N. " & err.ErrorNumber &_ " Message: " & err.ErrorText & " Line " & err.Line) Next 'Use the compiled assembly Dim RunObj As New Object Dim vArgs() As Object RunObj = Results.CompiledAssembly.CreateInstance( "Generated.ClassMain", False, Reflection.BindingFlags.CreateInstance, Nothing, vArgs, Nothing, Nothing) If Not RunObj Is Nothing Then RunObj.Esegui() Else MsgBox.Show("Compile Error") End If Else MsgBox.Show("Write VB.Net code to compile") End If Catch err As Exception MsgBox.Show(err.Message & " " & err.StackTrace) End Try