2009-05-23 72 views
1

我已经使用了内置在C#方法写入一个编译器,如下所示:常数误差的提供对象

CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp"); 
string Output = "Out.exe"; 
Button ButtonObject = (Button)sender; 

this.RadTextBox1.Text = string.Empty; 

System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); 

//Make sure we generate an EXE, not a DLL 
parameters.GenerateExecutable = true; 
parameters.OutputAssembly = Output; 

CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, RadTextBox1.Text); 

if (results.Errors.Count > 0) 
{ 
    RadTextBox2.ForeColor = Color.Red; 
    foreach (CompilerError CompErr in results.Errors) 
    { 
     RadTextBox2.Text = RadTextBox2.Text + 
        "Line number " + CompErr.Line + 
        ", Error Number: " + CompErr.ErrorNumber + 
        ", '" + CompErr.ErrorText + ";" + 
        Environment.NewLine + Environment.NewLine; 
    } 
} 

else 
{ 
    //Successful Compile 
    RadTextBox2.ForeColor = Color.Blue; 

    Guid guid =   Guid.NewGuid(); 

    string PathToExe = Server.MapPath(Path.Combine(@"\Compiled" , Output)); 

    FileStream fs = System.IO.File.Create(PathToExe); 

    using (StreamWriter sw = new StreamWriter(fs)) 
    { 
     sw.Write(RadTextBox1.Text); 
    } 

    Response.WriteFile(PathToExe); 

当运行该代码,写主方法(如代码http://msdn.microsoft.com/en-us/library/ms228506(VS.80).aspx,我得到此错误:

行号0,错误号:CS5001,'Program'c:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ Out.exe'不包含静态' Main'方法适用于入口点;

使用上面的代码作为我网站上编译器的基础(尚未生效)。所以你输入代码并生成一个.exe程序集。但是,当我将代码输入到代码写入的文本框(Radtextbox1)中时,即使使用主要方法,我也会得到该错误。

什么给?

感谢

+0

由于您的错误消息与Main方法有关,所以如果我们能够看到它,那将会很好。 – 2009-05-23 21:56:31

回答