I mentioned in an earlier post that I had some trouble creating setup projects for the x64 platform in Visual Studio and getting my MMC snap-in to register and install correctly. At the time I listed the following possible reasons for this:

  • The setup project behaving strangely when doing x64 builds
  • Me being stupid
  • Both of the above

After some digging I’m now quite confident to announce to all of my three four sporadic readers that I am not stupid. At least not in this regard.

The reason I was having such trouble is that a 32-bit version of InstallUtilLib is embedded in the MSI package even when I had it targeted for the x64 platform. When that embedded 32-bit version tried to run the CustomActions (register my 64-bit dll) things went downhill pretty fast resulting in a not so nice error message.

System.BadImageFormatException: Attempted to load a 64-bit assembly on a 32-bit platform. Use ReflectionOnlyLoad() instead if trying to load for reflection purposes.

To solve this issue a tool named Orca (part of the Windows SDK)  can be used to replace the embedded 32-bit version of InstallUtilLib with a 64-bit one. Heath Stewart’s post from early 2006 outlines the steps necessary to perform this surgical strike.

Good thing it’s two years and one Visual Studio release later.