Permanent error in compiler using C # objects
I've used C # built-in methods to write a compiler like:
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 the Main method (like example code at 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 method' Main 'suitable for entry point;
The above code is used as the basis for a compiler on my site (not live yet). This way you enter the code and generate the .exe assembly. But when I enter code into the text box to write code (Radtextbox1), even with the main method, I get an error.
What gives?
thanks
a source to share
The entry point function is special: you can't just add a method called "main" to the assembly. Instead, you must add an instance of type CodeEntryPointMethod to one of your classes.
See http://blogs.msdn.com/bclteam/archive/2005/10/01/475768.aspx for more information on some of the limitations of using the CodeEntryPointMethod method.
a source to share