Need expert help with System.BadImageFormatException: Invalid token

robplatt

Freshman
Joined
Jul 14, 2006
Messages
39
I've developed a pretty large vb.net 2.0 application. I wrote its own updater function using the webclient class. I post the new build on the server, up the version in a little version file and leave it at that.

The application (which is originally deployed with an installer) will check that text file on the webserver, if the version is larger, it will download the new exe, rename itself to old, rename the new exe to the original filename, then do an application.restart. upon restart the old file gets deleted. Works just fine on my dev machine.

On every one of my outside test machines (outside my network) I get the following error AFTER the new file has been downloaded, ran, and my "about" form is shown

************** Exception Text **************
System.InvalidOperationException: An error occurred creating the form. See Exception.InnerException for details. The error is: Invalid token. ---> System.BadImageFormatException: Invalid token.
at FOE.frmAbout.InitializeComponent()
at FOE.frmAbout..ctor()
--- End of inner exception stack trace ---
at FOE.My.MyProject.MyForms.Create__Instance__[T](T Instance)
at FOE.Form1.AboutToolStripMenuItem_Click(Object sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


thing is, every one of my other forms (10 or so) load fine. its just this ONE form will not load, and it throws the above exception.

So I took that downloaded file and did a hex comparison to the same build on my machine and found a few bytes to be different in two parts of the file. Also, I opened the "broken" exe with reflector and when i tried to view the frmAbout form the decompiler thew an exception as well.

I've rebuilt my application 3-4 different times, everytime its downloaded remotely, that area of it gets ... broken. If i zip it up that problem goes away (then i have to add the ability to unzip to my application to continue using the automatic update feature).


I have searched the web high and low and can not find anyone with this same problem. would someone please explain to me what exactly is going on and how i should go about getting around it?

If anyone things its a web server issue, im running 2000 with IIS5, and have old vb6 apps with similar autoupdate features built in that work fine (among the other 3-4 websites we host as well)...

anyways, i look forward to hearing someones opinion.
thanks.
 
If you strong name your exe and try again does it have any problems?

Is this particular form doing anything different to the rest, like loading other dlls / assemblies?
 
what do you mean strong name?

the two exe's im comparing are the same file, one on my dev machine, one downloaded from our server to a remote machine then sent back to me. during the download the exe changes slightly, always in the frmAbout_init area i guess. i just dont understand why or if im even correct. but thats what it looks like to me.
 
Giving the application a strong name is effectively signing it, this will (amongst other things) detect if the file is modified / corrupted in any way and is a good practice to get into anyway. Under VS 2005 you can do this by bringing up the applications property page and going to the Signing tab.
 
hmm. ok . there are options there. suggest what I should do, I'll do it and then test my app.

its strange to think that the rest of my app (so far) seems to work fine, but my about popup dialog throws the error..... all it has is our company logo, my name, # and a link to our website. simple. the rest of my app is about 2500 lines, syncing a remote sql server with a local mdb file, crystal reports, smtp connecting, its becoming quite extensive.

anyways. at the moment the clickonce checkbox is checked, and its issued to me, domain\administrator, and that expired a week ago.
 
I'm still waiting for a response. I'm not sure what the correct way to sign this file. The click once for some reason was already checked. I tried unchecking that and got the same problem.

As I stated earlier, the only problem I saw was raising that frmAbout form, however, I have ran into a few other problems throughout the program too. Downloading it really messes it up, unless its zipped. or downloaded directly to my machine.
 
Well, I changed my update path to my ssl path and that solved my problem. I wish I understood more what was actually happening, but now I can move on for the moment.
 
Back
Top