这个错误对我来说毫无意义。
我正在使用CodeDOM编译一个可执行文件。
using System;
using System.CodeDom.Compiler;
using System.IO;
using Microsoft.CSharp;
class Compiler
{
public static bool Compile(string[] sources, string output, params
string[] references)
{
var results = CompileCsharpSource(sources, "result.exe");
if (results.Errors.Count == 0)
return true;
else
{
foreach (CompilerError error in results.Errors)
Console.WriteLine(error.Line + ": " + error.ErrorText);
}
return false;
}
private static CompilerResults CompileCsharpSource(string[] sources,
string output, params string[] references)
{
var parameters = new CompilerParameters(references, output);
parameters.GenerateExecutable = true;
using (var provider = new CSharpCodeProvider())
return provider.CompileAssemblyFromSource(parameters, sources);
}
}
以下是我编译源代码的方式:
Compiler.Compile(srcList, "test.exe", new string[] { "System.dll", "System.Core.dll", "mscorlib.dll" });
下面是我正在编译的源代码中出现错误的部分:
System.Diagnostics.Process p;
if (System.Diagnostics.Process.GetProcessesByName("whatever").Length > 0)
p = System.Diagnostics.Process.GetProcessesByName("whatever")[0];
else
return false;