this is the error code i get
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)
when i try to load a simple windows form application(.net c#)
the code i use is this
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
}
So far i only managed to make it work for Form applications where i removed the Form and ran the code from the [STAThread] inside Program.cs, it didnt even work for a simple console application.
Any insight on this ?