如下所示,此方法here对大多数应用程序运行良好。从内存中执行WPF程序集
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应用程序。
您已重新命名用户控件文件或移动您的启动位置的文件,以不同的位置(在子文件夹)? – 2011-05-01 15:34:20