在保存之前,我必须检查(编译)类。现在它可以工作了,除非在所引用的类中有一个Shared
成员函数,然后它会中断。
这是使用中的代码摘录:
Dim _Errors As String = ""
Dim _CodeCompiler As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic")
Dim cp As CompilerParameters = New CompilerParameters()
Try
cp.ReferencedAssemblies.Add("System.ServiceModel.dll")
cp.ReferencedAssemblies.Add("System.ServiceModel.Web.dll")
cp.ReferencedAssemblies.Add("System.Data.dll")
cp.ReferencedAssemblies.Add("System.Web.Extensions.dll")
cp.ReferencedAssemblies.Add("System.Web.dll")
cp.ReferencedAssemblies.Add("System.dll")
cp.ReferencedAssemblies.Add("System.Xml.dll")
cp.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")
cp.ReferencedAssemblies.Add("System.Collections.dll")
cp.ReferencedAssemblies.Add("System.Configuration.dll")
cp.GenerateExecutable = False
cp.GenerateInMemory = True
cp.TreatWarningsAsErrors = False
Dim _CompilerResults As CompilerResults = Nothing
_CompilerResults = _CodeCompiler.CompileAssemblyFromSource(cp, final)
If (_CompilerResults.Errors.Count > 0) Then
For Each CompErr As CompilerError In _CompilerResults.Errors
_Errors += "Line number " + CompErr.Line.ToString() +
", Error Number: " + CompErr.ErrorNumber.ToString() +
", '" + CompErr.ErrorText + ";" + vbCrLf
Next
If _Errors <> "" Then
GC.Collect()
GC.WaitForPendingFinalizers()
File.AppendAllText(file_ & ".errors", _Errors)
File.WriteAllText(file_ + "." + Now.ToString("yyyy-MM-dd-HH-mm-ss"), final)
context.Response.Write(_Errors)
Exit Sub
End If
Else
GC.Collect()
GC.WaitForPendingFinalizers()
File.WriteAllText(file_, final)
context.Response.Write("DONE!")
End If
Finally
cp = Nothing
_CodeCompiler.Dispose()
End Try
该调用之后的_Errors变量得到:
“行号37,错误号:BC30456,” python“不是'Common'的成员。 &&vbCrLf&“行号50,错误号:BC30456,” python“不是'Common'的成员。 &vbCrLf&“行号87,错误号:BC30456,“ getFunctionFreindlyName”不是“ Common”的成员。” &vbCrLf&“行号88,错误号:BC30456,“ getFunctionFreindlyName”不是“ Common”的成员。” &vbCrLf&“行号98,错误号:BC30182,'预期类型。” &vbCrLf&“行号126,错误号:BC30456,“ getFunctionFreindlyName”不是“ Common”的成员。” &vbCrLf&“行号127,错误号:BC30456,“ getFunctionFreindlyName”不是“ Common”的成员。” &vbCrLf&“行号132,错误号:BC30456,“ getFunctionFreindlyName”不是“ Common”的成员。” &vbCrLf&“行号136,错误号:BC30456,“ getFunctionFreindlyName”不是“ Common”的成员。” &vbCrLf&“行号138,错误号:BC30182,'预期类型。” &&vbCrLf&“行号174,错误号:BC30182,'预期类型。” &vbCrLf&“行号203,错误号:BC30182,'预期类型。” &vbCrLf&“行号216,错误号:BC30182,'预期类型。” &vbCrLf&“行号235,错误号:BC30182,'预期类型。' &vbCrLf&“行号283,错误号:BC30182,'预期类型。” &vbCrLf&“行号298,错误号:BC30182,'预期类型。” &&vbCrLf&“行号318,错误号:BC30182,“预期类型”。 &vbCrLf&“行号336,错误号:BC30002,未定义'图像类型'。 &vbCrLf&“行号445,错误号:BC30182,'预期类型。 &vbCrLf&“行号450,错误号:BC30002,未定义'StringBuilder类型'。 &vbCrLf&“行号490,错误号:BC30182,'预期类型。” &vbCrLf&“行号511,错误号:BC30182,'预期类型。” &vbCrLf&“行号516,错误号:BC30002,未定义'Regex类型'。 &vbCrLf&“行号517,错误号:BC30002,未定义'类型'匹配'。 &vbCrLf&“行号523,错误号:BC30002,未定义'Regex类型'。 &vbCrLf&“行号534,错误号:BC30451,未声明“ Regex”。由于其保护级别,可能无法访问。” &vbCrLf&“行号535,错误号:BC30002,未定义'StringBuilder类型'。 &vbCrLf&“行号537,错误号:BC30451,未声明s”。由于其保护级别,它可能无法访问。 &vbCrLf&“行号565,错误号:BC30451,未声明” Regex”。由于其保护级别,可能无法访问。” &vbCrLf&“行号567,错误号:BC30451,未声明s”。由于其保护级别,可能无法访问。 &vbCrLf&“行号590,错误号:BC30451,未声明“ NewFuncname”。由于其保护级别,可能无法访问。” &vbCrLf&“行号611,错误号:BC30002,未定义'StringBuilder类型'。 &vbCrLf&“行号684,错误号:BC30456,“ WriteLocalLog”不是“ Common”的成员。” &vbCrLf&“行号687,错误号:BC30456,“ WriteLocalLog”不是“ Common”的成员。” &vbCrLf&“行号704,错误号:BC30002,'类型'System.Drawing.Imaging.ImageFormat'未定义。” &vbCrLf&“行号707,错误号:BC30002,'类型'System.Drawing.Image'未定义。“ &&vbCrLf&“行号718,错误号:BC30182,“预期类型”。 &vbCrLf&“行号783,错误号:BC30182,'预期类型。” &vbCrLf&“行号798,错误号:BC30182,'预期类型。” &vbCrLf&“行号815,错误号:BC30182,'预期类型。” &&vbCrLf&“行号834,错误号:BC30182,'预期类型。” &vbCrLf&“行号850,错误号:BC30182,'预期类型。” &vbCrLf&“行号924,错误号:BC30182,'预期类型。” &&vbCrLf&“行号1003,错误号:BC30182,'预期类型。” &vbCrLf&“行号1025,错误号:BC30182,'预期类型。” &vbCrLf&“行号1047,错误号:BC30182,'预期类型。” &vbCrLf&“行号1060,错误号:BC30182,'预期类型。 &vbCrLf&“行号1075,错误号:BC30182,'预期类型。” &vbCrLf&“”
那么如何告诉Codedom编译器该函数是IN Common.vb,它是Shared
?
答案 0 :(得分:0)
解决方案是在项目中包括对程序集的所有引用。现在,因为我实际上不知道应该添加哪个(尽管对于另一个类,我已经设法以某种方式找到了所有内容,并且进行了一些代码更改...)。因此,经过一番谷歌搜索之后,我发现了它,它运行良好:
For Each a As Reflection.Assembly In AppDomain.CurrentDomain.GetAssemblies()
If a.IsDynamic = False Then
cp.ReferencedAssemblies.Add(a.Location)
End If
Next