【发布时间】:2014-03-25 09:25:51
【问题描述】:
我的程序经常编译 c#-code,有时我得到一个 ArgumentException,例如“文件名 'C:\Users--\AppData\Local\Temp\wvpc3m5m.0.cs' 已经在集合中。参数名称:文件名”。
接下来是编译器的设置:
public void Init()
{
this.compilerParameters = new CompilerParameters
{
GenerateExecutable = false,
GenerateInMemory = true
};
}
编译:
public CompilerResults Compile(String code)
{
CompilerResults result = this.codeProvider
.CompileAssemblyFromSource(this.compilerParameters, code);
return result;
}
我认为codeProvider将传递的字符串写入文件,有时他会尝试在同一个文件中写入两次。
【问题讨论】:
-
保留 CodeProvider 是没有意义的。只需使用 new 运算符创建一个新的。
-
我这样做了,但是一直抛出异常
标签: c# compilation csharpcodeprovider