John
I didn't quite use the full example. I put some code behind a button
The code for the form I used is below, excluding the "Windows Form Designer generated code" region
The dll name is changing becauses it's creating a temporary file to hold the code, this is then invoked
If you still get the same problem put a try/catch round the lot and print the full exception in the command window. If you post the full exception I'll have a look but can't promise anything
Let me know how you get on
Chris
Imports Syste
Imports System.Tex
Imports System.CodeDom.Compile
Imports System.Reflectio
Imports System.I
Imports Siclops.Data.sicSystemOption
Public Class Form
Inherits System.Windows.Forms.For
#Region " Windows Form Designer generated code
#End Regio
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Clic
Dim c As VBCodeProvider = New VBCodeProvide
Dim icc As ICodeCompiler = c.CreateCompiler(
Dim cp As CompilerParameters = New CompilerParameter
cp.ReferencedAssemblies.Add("system.dll"
cp.ReferencedAssemblies.Add("system.xml.dll"
cp.ReferencedAssemblies.Add("system.data.dll"
' Sample code for adding your own referenced assemblie
'cp.ReferencedAssemblies.Add("c:\yourProjectDir\bin\YourBaseClass.dll"
'cp.ReferencedAssemblies.Add("YourBaseclass.dll"
cp.CompilerOptions = "/t:library
cp.GenerateInMemory = Tru
Dim sb As StringBuilder = New StringBuilder(""
sb.Append("Imports System" & vbCrLf
sb.Append("Imports System.Xml" & vbCrLf
sb.Append("Imports System.Data" & vbCrLf
sb.Append("Imports System.Data.SqlClient" & vbCrLf
sb.Append("Namespace myNamespace " & vbCrLf
sb.Append("Class myLib " & vbCrLf
sb.Append("Public Function UsersCode() As Object " & vbCrLf
'sb.Append("YourNamespace.YourBaseClass thisObject = New YourNamespace.YourBaseClass()"
sb.Append(vbCode() & vbCrLf
sb.Append("End Function " & vbCrLf
sb.Append("End Class " & vbCrLf
sb.Append("End Namespace" & vbCrLf
Debug.WriteLine(sb.ToString()) ' look at this to debug your eval strin
Dim cr As CompilerResults = icc.CompileAssemblyFromSource(cp, sb.ToString()
Dim a As System.Reflection.Assembly = cr.CompiledAssembl
Dim o As Objec
Dim mi As MethodInf
o = a.CreateInstance("myNamespace.myLib"
Dim t As Type = o.GetType(
mi = t.GetMethod("UsersCode"
Dim s As Objec
s = mi.Invoke(o, Nothing
MsgBox(s.GetType.ToString
End Su
Private Function vbCode() As Strin
Dim v As Strin
v = "Dim strConn As String = " & Chr(34) & "Server=(local);dataBase=Northwind;User id=sa;Password=;" & Chr(34
v &= vbCrLf & "Dim cmd As New SqlCommand()
v &= vbCrLf & "Dim cn As New SqlConnection(strConn)
v &= vbCrLf & "cn.Open()
v &= vbCrLf & "cmd.Connection = cn
v &= vbCrLf & "cmd.CommandText = " & Chr(34) & "select * from employees" & Chr(34
v &= vbCrLf & "cmd.CommandType = CommandType.Text
v &= vbCrLf & "Dim ds As DataSet = New DataSet()
v &= vbCrLf & "Dim da As New SqlDataAdapter()
v &= vbCrLf & "da.SelectCommand = cmd
v &= vbCrLf & "da.Fill(ds)
'v &= vbCrLf & "Microsoft.VisualBasic.MsgBox(" & Chr(34) & "About to return" & Chr(34) & ")
v &= vbCrLf & "Return ds
Return
End Functio
End Clas