我想加載另一個C#窗體窗體應用程序,這是我用當前窗體窗體應用程序創建的。我想從內存中加載它。但是,我遇到:TargetInvocationException從內存中加載Exe時
型「System.Reflection.TargetInvocationException」未處理的異常出現在mscorlib.dll 附加信息:異常已通過調用的目標引發異常。
private void button1_Click(object sender, EventArgs e)
{
FileStream _FileStream = new FileStream("load.exe", FileMode.Open);
BinaryReader _BinaryReader = new BinaryReader(_FileStream);
byte[] bBytes = _BinaryReader.ReadBytes(Convert.ToInt32(_FileStream.Length));
_BinaryReader.Close();
_FileStream.Close();
Assembly a = Assembly.Load(bBytes);
MethodInfo method = a.EntryPoint;
if (method != null)
{
object o = a.CreateInstance(method.Name);
method.Invoke(o,null);
}
}
嗨,當你說「你的WindowsForm應用程序」,你指的是哪一個?如果我在控制檯窗口應用程序中編碼它,並嘗試從內存執行「load.exe」,它的工作原理。但是,如果我使用Windows窗體應用程序從內存執行「load.exe」,它會失敗。 – RStyle
我在說你要加載的應用程序 – Tigran