I have created an installer with Visual Studio 2008. VS project type is deployment project. This installer fails in some environments but also runs perfectly in some other environments.
For example, the installer is compiled in virtual machine that runs Windows Server 2012 R2 Standard. Of course installation succeeds there. How ever, it fails in other virtual machine running same Windows edition.
The error message is: "Error 1001. Exception occurred while initializing the installation: System.BadImageFormatException: Could not load file or assembly 'file: Custom actions.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."
Target framework is 3.5 in all applications in the installer solution. Also the references in Custom Actions library have .NET version 2.0 or 3.5.
What is missing in the failing environment? Where to start the search?
Blog: Maybe check this blog quickly. Essentially: 1) bitness 32/64
, 2) corrupted binary file
or 3) configuration issues
(app.config
).
InstallUtilLib.dll: Here is a similar answer: System.BadImageFormatException: Could not load file or assembly (from installutil.exe). It links to this MSDN explanation: 64-bit managed custom actions throw a System.BadImageFormatException exception. Seems likely.
Alternatives: The real answer - IMHO - would be to avoid Visual Studio Installer projects due to a number of known problems with this type of project. The WiX toolkit is a good open source alternative. And there are other, commercial options. And there is an alternative version with more elaborate details.
Some Links:
- System.BadImageFormatException: Could not load file or assembly
- BadImageFormatException Class
- This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded
There are really only two reasons for this error:
You have 32-bit (or 64-bit) code trying to call an assembly of the opposite architecture. In custom action calls you'll need to chase down the calling sequence and be careful of AnyCpu types of assembly that may be JIT compiled to the architecture of the system rather than assemblies you'll call.
Incompatible NET architectures. In your case, the assemblies you referred to are all NET 2.0 CLR-based. If they end up running in a NET 4.0 CLR they will fail. It may help to look at the Launch Conditions to see what's going on.
I also think Visual Studio 2008 is not a good basis for a setup project. VS Community Edition is free, and will host the add-on Installer Projects. Certainly VS 2008 is unaware of NET 4.0 CLR.