BadImageFormatException x64 Issue

Ken Tola picture Ken Tola · Apr 23, 2012 · Viewed 10.5k times · Source

I swear the more Microsoft "evolves" Visual Studio, the more ignorant the entire process becomes.

I have a Windows Service with 3 class libraries in it. I went into the properties for each class library and set the platform target to x64. I did this same thing to the Windows Service as well as to the Test Console project I added to verify everything.

I can run the console application on my Windows 2008 R2 x64 server with no issues but the stupid installer keeps bombing out and telling me that I have a bad image. I did ensure that I had set the target platform of the installer to x64.

I have no idea idea was this stupid thing would be bombing out and would really appreciate any insights. I do reference other DLLs and those might be x86 but I thought if the main libraries were set properly that things would work...

Answer

Ken Tola picture Ken Tola · Apr 23, 2012

I have finally figured this out – it has NOTHING to do with architecture, references or any other nonsense and everything to do with the installer itself. As this article explains – the Visual Studio Installer, by default, uses a 32 bit DLL and that is what causes the failures.

To overcome this problem, simply follow these steps:

  1. Make sure that you go into the Properties ⇒ Build tab for every project and set the Target Platform to x64
  2. Click on the name of your Installation project and then Properties and ensure that the Target Platform is x64
  3. Build your solution – if the solution does not compile, right click and Unload Project and then Load Porject for those projects whose references fail.
  4. Go here and download and install the 7.0 INstaller SDK
  5. Go into the C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin folder and install Orca by double-clicking on the Orca.Msi file
  6. Run Orca and open your project's MSI folder
  7. Select the Binary table
  8. Double click the cell [Binary Data] for the record InstallUtil
  9. Make sure "Read binary from filename" is selected
  10. Click the Browse button Browse to C:\Windows\Microsoft.NET\Framework64\v4.0.30319
  11. Select InstallUtilLib.dll
  12. Click the Open button and then the OK button

That is it - save your MSI file in Orca and then deploy it – the x64 installation should work without any further issues.