C# not recognizing my variable -
i'm trying load code exe file create new .exe file. it's not recognizing variable "sourcecode". says name "sourcecode" not exist in current context
private void button1_click(object sender, eventargs e) { using (filestream sourcecode = new filestream("thecode.exe", filemode.open, fileaccess.readwrite, fileshare.none)); string output = textbox3.text; string[] assembly = { "system.dll", "system.drawing.dll", "system.windows.forms.dll" }; codedomprovider codecompiler = codedomprovider.createprovider("csharp"); compilerparameters parameters = new compilerparameters(assembly, ""); parameters.outputassembly = output; parameters.generateexecutable = true; parameters.generateinmemory = false; parameters.warninglevel = 3; parameters.treatwarningsaserrors = true; parameters.compileroptions = "/optimize+ /target:winexe"; string errors = null; try { compilerresults results = null; results = codecompiler.compileassemblyfromsource(parameters, sourcecode); //this here giving me error if (results.errors.count > 0) { errors = ""; foreach (system.codedom.compiler.compilererror compileerror in results.errors) { errors += "line number " + compileerror.line + ", error number: " + compileerror.errornumber + ", '" + compileerror.errortext + ";\r\n\r\n"; }
the following line ending semicolon ';'
using (filestream sourcecode = new filestream("thecode.exe", filemode.open, fileaccess.readwrite, fileshare.none));
in c# semicolon statement terminator rather line terminator. should declare using statements this
using(var bar = new foo()) { }
thus making code:
using (filestream sourcecode = new filestream("thecode.exe", filemode.open, fileaccess.readwrite, fileshare.none)) { }
Comments
Post a Comment