VBCodeProvider

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabriel Ferrarini

    VBCodeProvider

    When I compile the following code, it works fine only one time. At the
    second time the following error occurs.

    Can somebody help me?

    vbc : Command line (0,0) : error BC2006: option 'r' requires ':<file_list>'



    =============== =============== ===
    Public Function Eval(ByVal vbCode As String) As Object

    Dim oCodeProvider As VBCodeProvider = New VBCodeProvider

    ' Obsolete in 2.0 framework

    ' Dim oICCompiler As ICodeCompiler = oCodeProvider.C reateCompiler

    Dim oCParams As CompilerParamet ers = New CompilerParamet ers

    Dim oCResults As CompilerResults

    Dim oAssy As System.Reflecti on.Assembly

    Dim oExecInstance As Object = Nothing

    Dim oRetObj As Object = Nothing

    Dim oMethodInfo As MethodInfo

    Dim oType As Type



    Try

    ' Setup the Compiler Parameters

    ' Add any referenced assemblies

    Dim asm As [Assembly]

    For Each asm In AppDomain.Curre ntDomain.GetAss emblies()

    oCParams.Refere ncedAssemblies. Add(asm.Locatio n)

    Next

    oCParams.Compil erOptions = "/t:library"

    oCParams.Genera teInMemory = True

    ' Generate the Code Framework

    Dim sb As StringBuilder = New StringBuilder(" ")

    sb.Append("Impo rts System" & vbCrLf)

    sb.Append("Impo rts System.Xml" & vbCrLf)

    sb.Append("Impo rts System.Data" & vbCrLf)

    ' Build a little wrapper code, with our passed in code in the middle

    sb.Append("Name space dValuate" & vbCrLf)

    sb.Append("Clas s EvalRunTime " & vbCrLf)

    sb.Append("Publ ic Function EvaluateIt() As Object " & vbCrLf)

    sb.Append(vbCod e & vbCrLf)

    sb.Append("End Function " & vbCrLf)

    sb.Append("End Class " & vbCrLf)

    sb.Append("End Namespace" & vbCrLf)

    Debug.WriteLine (sb.ToString())

    Try

    ' Compile and get results

    ' 2.0 Framework - Method called from Code Provider

    oCResults = oCodeProvider.C ompileAssemblyF romSource(oCPar ams, sb.ToString)

    ' 1.1 Framework - Method called from CodeCompiler Interface

    ' cr = oICCompiler.Com pileAssemblyFro mSource (cp, sb.ToString)



    ' Check for compile time errors

    If oCResults.Error s.Count <0 Then

    Me.CompilerErro rs = oCResults.Error s

    Throw New Exception("Comp ile Errors")

    Else

    ' No Errors On Compile, so continue to process...

    oAssy = oCResults.Compi ledAssembly

    oExecInstance = oAssy.CreateIns tance("dValuate .EvalRunTime")



    oType = oExecInstance.G etType

    oMethodInfo = oType.GetMethod ("EvaluateIt ")

    oRetObj = oMethodInfo.Inv oke(oExecInstan ce, Nothing)

    Return oRetObj

    End If

    Catch ex As Exception

    ' Compile Time Errors Are Caught Here

    ' Some other weird error

    Debug.WriteLine (ex.Message)

    Stop

    End Try

    Catch ex As Exception

    Debug.WriteLine (ex.Message)

    Stop

    End Try

    Return oRetObj

    End Function


Working...