【发布时间】:2011-05-01 15:25:48
【问题描述】:
这种方法here(如下所示)适用于大多数应用程序。
FileStream fs = new FileStream(filePath, FileMode.Open); // read the bytes from the application EXE file
BinaryReader br = new BinaryReader(fs);
byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length));
fs.Close();
br.Close();
Assembly a = Assembly.Load(bin); // load the bytes into Assembly
MethodInfo method = a.EntryPoint; // search for the Entry Point
if (method != null)
{
// create an instance of the Startup form Main method
object o = a.CreateInstance(method.Name);
// invoke the application starting point
method.Invoke(o, null); //EXCEPTION THROWN HERE
}
但是,当我尝试使用它来启动 WPF 应用程序时,抛出了异常:
Exception has been thrown by the target of an invocation.
内部异常是 System.IO.IOException 类型:
Cannot locate resource 'mainwindow.xaml'.
注意:应用程序可以正常运行。出于测试目的,编译了一个空的 wpf 应用程序。
【问题讨论】:
-
您是否重命名了您的用户控件文件或将您的启动位置文件移动到不同的位置(在子文件夹中)?
标签: wpf reflection .net-assembly