Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

visual studio 2010 - System.BadImageFormatException When Installing Program From VS2010 Installer Project

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

  1. Open the resulting .msi in Orca from the Windows Installer SDK.
  2. Select the Binary table.
  3. Double click the cell [Binary Data] for the record InstallUtil.
  4. Make sure "Read binary from filename" is selected and click the Browse button.
  5. Browse to %WINDIR%Microsoft.NETFramework64v2.0.50727.
  6. The Framework64 directory is only installed on 64-bit platforms and corresponds to the 64-bit processor type.
  7. Select InstallUtilLib.dll.
  8. Click the Open button.
  9. Click the OK button.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...