c# - Assembly.Load throws a bad format exception if i load a winform application -


this error code get

system.badimageformatexception: impossible load file or assembly '6632 bytes loaded quick test 2, version=1.0.0.0, culture=neutral, publickeytoken=null' or 1 of dependencies. attempt load program in bad format. nome file: '6632 bytes loaded 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 try load simple windows form application(.net c#)

the code use 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 managed make work form applications removed form , ran code [stathread] inside program.cs, didnt work simple console application.

any insight on ?

it can typically occur when changed target framework of .csproj , reverted started with. before ever , go crazy trying google right solution make sure :

  1. check if supportedruntime version="a different runtime cs project target" under startup tag in app.config.

  2. that means checking other autogenerated or other files in may properties folder see if there no more runtime mismatch between these files , 1 defined in .csproj file.

these might save lot of time before start trying different things project properties overcome error.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -