これは私が得るエラーコードです
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]からコードを実行したフォームアプリケーションでのみ機能させることができましたが、単純なコンソールアプリケーションでも機能しませんでした。
これに関する洞察はありますか?