CodeDomProvider strange error
-
Thursday, December 03, 2009 9:31 PM
I am using this code which I copied from MSDN site with only slight modifications.
private void pushCompile_Click ( object sender, EventArgs e )
{
if ( this.txtSourceFilesForCompilation.Text == "" )
{
TSP.textToSpeech ( "Source files text box is empty" );
return;
}
CodeDomProvider codeProvider;
codeProvider = CodeDomProvider.CreateProvider ( "C#" );
string Output = "Out.dll";
Button ButtonObject = ( Button )sender;
this.txtResourceFilesToCompile.Text = "";
System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters ( );
switch ( this.pushCompileOptions.Text )
{
case "Generate Executable":
parameters.GenerateExecutable = true;
break;
case "Generate Dll":
parameters.GenerateExecutable = false;
break;
}
parameters.OutputAssembly = Output;
CompilerResults results = codeProvider.CompileAssemblyFromSource ( parameters, this.txtSourceFilesForCompilation.Text );if ( results.Errors.Count > 0 )
{
this.txtResourceFilesToCompile.ForeColor = Color.Red;
foreach ( CompilerError CompErr in results.Errors )
{
this.txtResourceFilesToCompile.Text = this.txtResourceFilesToCompile.Text +
"Line number " + CompErr.Line +
", Error Number: " + CompErr.ErrorNumber +
", '" + CompErr.ErrorText + ";" +
Environment.NewLine + Environment.NewLine;
}
}
else
{
//Successful Compile
this.txtResourceFilesToCompile.ForeColor = Color.Blue;
this.txtResourceFilesToCompile.Text = "Success!";
if ( ButtonObject.Text == "Run" ) Process.Start ( Output );
}
} // pushCompile_Click
No matter what file I want to compile and I want to compile to a dll I get this error:
Line number 1, Error Number: CS1056, 'Unexpected character '\';
There is no back slash anywhere in my files on line 1.
What is the problem with the code?
Thanks.
AlexB
All Replies
-
Friday, December 04, 2009 11:58 AMModerator
Hello Alex,
I haven't played with CodeDom, but would you mind providing the MSDN article where you get these codes? I'd like to have a test in my side and then report back to you. :-)
By the way, our team are doing a project named all-in-one code framework. It includes many sample project. Once, one of my colleagues wrote a c# CodeDom sample project. So if you are interesting, you can download it from the following link and see how that project works.http://cfx.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28718
Hope that helps!
Ji ZhouMSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
Friday, December 04, 2009 1:50 PMJi hi,
Absurdly, I cannot find it. I believe I copied it from a website yesterday, changed one class method because it was obsolete and failed to copy the link. I will keep looking but it seems to be a matter of luck. I don't exactly remember the keywords I used. I tried many and so far no luck, sorry.
Thank you for your help.
Could you give a brief overview of what I can expect to all-in-one in terms of capabilities?
Thanks.
AlexB -
Monday, December 07, 2009 10:42 AMModerator
Could you give a brief overview of what I can expect to all-in-one in terms of capabilities?
Thanks.
AlexB
Sure. All-in-one code framework is a samples collection. Just download this release,
http://cfx.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28718#DownloadId=71654
And you will find a sample CSCodeDom project in it. This sample project shows how to compile codes dynamically and then use it via Reflection. I quote the project's ReadMe.txt as follows,
"The CSCodeDOM project demonstrates how to use the .NET CodeDOM mechanism to
enable dynamic souce code generation and compilation at runtime.The ScriptControl class included in this project accepts a piece of code
written in C#/VB.NET/JScript and dynamically generates method & class wrapper
for the code. Then the dynamically generated code will be compiled into
an in-memory assembly. The compiled code then can be called via reflection.The MainForm class in this project provides a simple UI for testing the
ScriptControl class."
Best regards,
Ji Zhou
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer by AlexBB - Vista Ult64 SqlSer64 WinSer64 Monday, December 07, 2009 2:44 PM
-
Friday, February 10, 2012 7:14 PM
hi ji
is it possible to decompile .Net exe,if yes please tell me how???
Mahesh

