我正在做的事情是:
byte[] bytes = File.ReadAllBytes(@Application.StartupPath+"/UpdateMainProgaramApp.exe");
Assembly assembly = Assembly.Load(bytes);
// load the assemly
//Assembly assembly = Assembly.LoadFrom(AssemblyName);
// Walk through each type in the assembly looking for our class
MethodInfo method = assembly.EntryPoint;
if (method != null)
{
// create an istance of the Startup form Main method
object o = assembly.CreateInstance(method.Name);
// invoke the application starting point
try
{
method.Invoke(o, null);
}
catch (TargetInvocationException e)
{
Console.WriteLine(e.ToString());
}
}
问题在于它抛出了
TargetInvocationException
异常——它发现这个方法是主方法,但由于这一行而抛出了此异常:object o = assembly.CreateInstance(method.Name);
o
仍然为空。所以我深入研究了一下堆栈跟踪,实际的错误是:
InnerException = {"在程序中创建第一个 IWin32Window 对象之前应调用 SetCompatibleTextRenderingDefault"}(这是我的翻译,因为它给我提供了一半希伯来语和一半英语的堆栈跟踪,因为我的 Windows 是希伯来语。)
我做错了什么?
code
object oo = assembly.CreateInstance("Init");code
但是对象"oo"仍然为空-为什么? - Eli Braginskiycode
_Type = assembly.GetType("UpdateMainProgaramApp");code
,我应该写命名空间(UpdateMainProgramApp)还是因为这是我的类:code
public partial class Form1 : Formcode
,我应该写“Form1”?因为我尝试了两种方式,但_Type仍然为空... - Eli Braginskiy