Constant error in compiler using C#'s provided objects
- by dotnetdev
I have used the built in C# methods to write a compiler, like the following:
    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);
When I run this code and write a Main method (such as the code sample in http://msdn.microsoft.com/en-us/library/ms228506(VS.80).aspx, I get this error:
Line number 0, Error Number: CS5001, 'Program 'c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Out.exe' does not contain a static 'Main' method suitable for an entry point;
The code above is used as the basis of a compiler on my site (not yet live). So you type in code and generate an .exe assembly. But when I enter code into the textbox for code writing (Radtextbox1), even with a main method, I get the error.
What gives?
Thanks