【发布时间】:2017-08-03 17:16:41
【问题描述】:
这个错误对我来说完全没有意义。 我正在使用 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;
所以我在编译时引用了 System.dll,并且我在进程前面编写了 System.Diagnostics(我也尝试使用 System.Diagnostics,但我产生了类似且不太具体的错误),并且出于某种原因我收到这个错误。我将不胜感激。
【问题讨论】:
标签: c# .net codedom system.diagnostics