I am getting this error when trying to install a Windows Service from a VS2010 .NET 4 Installer project:
"Exception occurred while initializing the installation: System.BadImageFormatException. Could not load the file [file name].exe or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."
I can't figure out what is causing this. All the projects in my solution are compiling against .NET Framework 4 and the installer solution dependencies require .NET 4. I have cleaned/rebuilt the solutions and projects to no avail. Is there something obvious I am missing?
This can happen if your installer is installing 64-bit dlls.
If you add a 64-bit managed custom action to a Setup project, the Visual Studio build process embeds a 32-bit version of InstallUtilLib.dll into the MSI as InstallUtil. In turn, the 32-bit .NET Framework is loaded to run the 64-bit managed custom action and causes a BadImageFormatException exception.
For the workaround, replace the 32-bit InstallUtilLib.dll with the 64-bit version.
You likely have the wrong installer prerequisites. Go to your setup project's properties window, click Prerequisites... under build, and ensure that .NET Framework 4 is checked. You likely still have .NET Framework 3.5 SP1 still checked. You probably need to use Windows Installer 4.1 as well (in the same dialog).
Also check to make sure that in launch conditions your .NET Framework version points to 4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With