使用Microsoft.VisualBiasic.VBCodeProvider.CompileAssemblyFromSource时找不到文件错误

时间:2014-10-15 16:43:56

标签: .net vb.net reflection

我正在创建一个内存.NET DLL,它执行基于函数Foo()的动态代码,该动态代码已经过验证,没有任何语法/运行时错误。此方法99%的时间都有效,但有时以下代码会抛出以下错误:

Could not find file 'C:\Users\[user]\AppData\Local\Temp\[random string].dll'

例如:

Could not find file 'C:\Users\mike\AppData\Local\Temp\y2u4taxq.dll'

以下是抛出错误的代码。我无法找到特定的代码行,因为这只发生在生产中,我不会得到问题的通知,直到为时已晚。

Try
    ' Setup the Compiler Parameters  
    ' Add any referenced assemblies
    With oCParams
        .ReferencedAssemblies.Add("System.dll")
        .ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")
        .ReferencedAssemblies.Add("Microsoft.VisualBasic.Compatibility.dll")

        .CompilerOptions = "/t:library"
        .GenerateInMemory = True
        .IncludeDebugInformation = True
    End With

    ' Compile and get results 
    oCResults = oCodeProvider.CompileAssemblyFromSource(oCParams, code)

    ' Check for compile time errors 
    If oCResults.Errors.Count <> 0 Then

        Dim CompilerError As CompilerError
        CompilerError = oCResults.Errors(0)
        Throw New Exception(CompilerError.ErrorText)

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

        oAssy = oCResults.CompiledAssembly
        oExecInstance = oAssy.CreateInstance(NamespaceName & "." & ClassName)

        oRetObj = CallByName(oExecInstance, "Foo", CallType.Method, Parameters)
        Return oRetObj

    End If

Catch ex As Exception
    ' RunTime Errors Are Caught Here
    Throw ex

End Try

0 个答案:

没有答案