【发布时间】:2010-10-23 22:37:10
【问题描述】:
我正在努力让我的客户通过下载字节并使用反射打开另一个程序来打开它。我目前已经在 C# 控制台应用程序上进行了此操作,但是当我尝试在 Windows 窗体应用程序上执行此操作时出现此错误。
“调用的目标已抛出异常。”
这里是代码
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);
}
【问题讨论】:
-
您能否提供堆栈跟踪(以及内部异常的详细信息,如果有)?
标签: c# .net reflection assemblies byte