Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to get a service I've written to install and keep getting the following error when it is built for any CPU:

Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly '; or one of its dependencies. An attempt was made to load a program with an incorrect format..


This only happens on my machine. My co-worker has no issues on his. If I build it for 32 bit it works fine on mine. It's has us stumped and I'm not sure where the best place to start looking for the problem is other than my computer. One solution I tried was a complete wipe, install, update, etc. of everything.

Thanks in advance for help provided.

*Edit
I don't think it's an issue with the assemblies because my co-worker can build and run it fine for any CPU. The problem seems limited to the machine I work on.
Posted
Updated 12-Jun-12 10:07am
v2
Comments
Zoltán Zörgő 12-Jun-12 16:17pm    
You are sure, that all your assamblies are the same on both machines?
guitaristjason 12-Jun-12 16:28pm    
I double checked with my co-worker to be sure, but yes, they are the same.
Zoltán Zörgő 13-Jun-12 2:21am    
Try to check with a dependency walker on both machines:
http://www.netomatix.com/development/DependsNet.aspx
http://checkasm.booring.net/default.aspx
http://www.dependencywalker.com/
... there are more of these...

If your application is compiled as "AnyCPU", it will always run only as x64 process on x64 system. You can install only x64 dependent assemblies in your installer (the x86 binaries will never be used on x64 OS). You can not mix them.
You probably have an x64 machine, but your application depends on some x86 assamblies. If you compile to x86, all assamblies will have the same platform.
 
Share this answer
 
There are a number of possible issues here, most of which revolve around the x86/x64 issue. If you have dlls that are 32-bit dependent but you try to use AnyCPU, you will get this error. If you try to use a 64-bit installer when the app compiles as 32-bit, you will get this error. The list goes on. Here are a couple Stack Overflow questions with some great answers and possible solutions:

http://stackoverflow.com/questions/323140/system-badimageformatexception-invalid-format-when-trying-to-install-service-w[^]

http://stackoverflow.com/questions/5229310/system-badimageformatexception-could-not-load-file-or-assembly[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900