[英]Get type or namespace not found CodeDom
我已經面臨這個問題幾個小時了。
我正在玩一些代碼域,但我得到:找不到類型或名稱空間線程。
我的編譯器代碼是這個:
using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CodeDom
{
public class Compiler
{
public Compiler(string sourceCode, string savePath)
{
string[] referencedAssemblies = new string[] { "System.dll", "System.Windows.Forms.dll", "System.Threading.Thread.dll" };
Dictionary<string, string> providerOptions = new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } };
string compilerOptions = "/target:winexe /platform:anycpu /optimize+";
using (CSharpCodeProvider cSharpCodeProvider = new CSharpCodeProvider(providerOptions))
{
CompilerParameters compilerParameters = new CompilerParameters(referencedAssemblies)
{
GenerateExecutable = true,
GenerateInMemory = false,
OutputAssembly = savePath,
CompilerOptions = compilerOptions,
TreatWarningsAsErrors = false,
IncludeDebugInformation = false,
};
CompilerResults compilerResults = cSharpCodeProvider.CompileAssemblyFromSource(compilerParameters,sourceCode); // source.cs
if (compilerResults.Errors.Count > 0)
{
foreach (CompilerError compilerError in compilerResults.Errors)
{
MessageBox.Show(string.Format("{0}\nLine: {1} - Column: {2}\nFile: {3}", compilerError.ErrorText,
compilerError.Line, compilerError.Column, compilerError.FileName));
}
return;
}
else
{
MessageBox.Show("Compiled!");
}
}
}
}
}
我不明白,我已經正確引用了 dll System.Threading.Thread.dll 但它仍然找不到它。
你可以試試System.Threading.dll
它應該沒有Thread
的名稱。
我使用了您的兩種解決方案,但仍然出現此錯誤。
string[] referencedAssemblies = new string[] { "System.dll", "System.Windows.Forms.dll", "mscorlib.dll" , "System.Threading.dll" };
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.