I am working on making my client open another program by downloading the bytes and using reflection to open it. I have currently got this working on a C# Console Application, but when I try and do it on a Windows Form Application I get this error.
"Exception has been thrown by the target of an invocation."
Here is the code
using System;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
private void listBox1_DoubleClick(object sender, EventArgs e)
{
if (listBox1.SelectedItem.ToString() != null)
{
if (MessageBox.Show("Run " + listBox1.SelectedItem.ToString() + "?", "Run this program?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
byte[] bytes;
using (WebClient client = new WebClient())
{
bytes = client.DownloadData(new Uri("http://example.net/program.exe"));
}
RunFromBytes(bytes);
}
}
}
private static void RunFromBytes(byte[] bytes)
{
Assembly exeAssembly = Assembly.Load(bytes);
exeAssembly.EntryPoint.Invoke(null, null);
}