这是我得到的错误代码
System.BadImageFormatException: impossible to load the file or assembly '6632 bytes loaded from quick test 2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Attempt to load a program in a bad format.
Nome file: '6632 bytes loaded from quick test 2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ---> System.BadImageFormatException: Format IL not correct.
in System.Reflection.Assembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection)
in System.Reflection.Assembly.Load(Byte[] rawAssembly)
in quick_test_2.Form1.button2_Click(Object sender, EventArgs e) in C:\Users\HHH\Documents\Visual Studio 2010\Projects\quick test 2\quick test 2\Form1.cs:riga 175
in System.Windows.Forms.Control.OnClick(EventArgs e)
in System.Windows.Forms.Button.OnClick(EventArgs e)
in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
in System.Windows.Forms.Control.WndProc(Message& m)
in System.Windows.Forms.ButtonBase.WndProc(Message& m)
in System.Windows.Forms.Button.WndProc(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
in System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
当我尝试加载一个简单的 Windows 窗体应用程序(.net c#)
我使用的代码是这个
try
{
Assembly myAsm = Assembly.Load(File.ReadAllBytes("myFile.exe"));
MethodInfo myMethod = assm.EntryPoint;
object myObj = assm.CreateInstance(myMethod.Name);
myMethod.Invoke(o, null);
}
catch
{
//error
}
到目前为止,我只设法使它适用于我删除表单并从 Program.cs 中的 [STAThread] 运行代码的表单应用程序,它甚至不适用于简单的控制台应用程序。
对此有任何见解吗?