Installer created by VS 2008 deployment project fails with error “System.BadImageFormatException”

非 Y 不嫁゛ 提交于 2019-12-11 06:19:33

问题


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?


回答1:


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



回答2:


There are really only two reasons for this error:

  1. 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.

  2. 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.



来源:https://stackoverflow.com/questions/52830784/installer-created-by-vs-2008-deployment-project-fails-with-error-system-badimag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!