I want to download the code from http://pastehtml.com/view/awono3xoq.txt, save it to a string, then compile & run it when the button is clicked, but I can’t seem to get the code below to work:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.IO;
using System.Diagnostics;
using System.Net;
using System.Runtime.InteropServices;
namespace ASV
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void compile()
{
CSharpCodeProvider myCodeProvider = new CSharpCodeProvider();
ICodeCompiler myCodeCompiler = myCodeProvider.CreateCompiler();
String [] referenceAssemblies = {"System.dll"};
string myAssemblyName = "Assembly.exe";
CompilerParameters myCompilerParameters = new CompilerParameters(referenceAssemblies, myAssemblyName);
myCompilerParameters.GenerateExecutable = true;
myCompilerParameters.GenerateInMemory = true;
WebClient x = new WebClient();
Stream y = x.OpenRead("http://pastehtml.com/view/awono3xoq.txt");
StreamReader z = new StreamReader(y);
string source = z.ReadToEnd();
z.Close();
y.Close();
CompilerResults compres = myCodeCompiler.CompileAssemblyFromSource(myCompilerParameters, source);
Process.Start("Assembly.exe");
}
private void button1_Click(object sender, EventArgs e)
{
compile();
}
}
}
what am I doing wrong (other than having too many using statments :P)?
If you check
CompilerResults compresit shows that there’s an exception and the compilation was not successful and hence it’s not writing outAssembly.exeand there is aSystem.IO.FileNotFoundexception fromProcess.Start()Try this