System.Data.OracleClient not working in 64 bit machines when built in 32 bit machines web setup project with custom action where target platform = x64
December 17, 2010 1 Comment
The issue is that if you build a managed class library project targeting a 64-bit platform using /platform:x64 or /platform:Itanium and install a Windows Installer package built in Visual Studio 2005 on a 64-bit machine a System.BadImageFormatException is thrown.
When you build the Windows Installer project in Visual Studio 2005 it embeds the 32-bit version of InstallUtilLib.dll into the Binary table as InstallUtil.
To workaround this issue you either need to import the appropriate bitness of InstallUtilLib.dll into the Binary table for the InstallUtil record or – if you do have or will have 32-bit managed custom actions add it as a new record in the Binary table and adjust the CustomAction table to use the 64-bit Binary table record for 64-bit managed custom actions.
To replace the 32-bit InstallUtilLib.dll with the 64-bit bitness,
- Open the resulting .msi in Orca from the Windows Installer SDK
- Select the Binary table
- Double click the cell [Binary Data] for the record InstallUtil
- Make sure "Read binary from filename" is selected and click the Browse button
- Browse to %WINDIR%\Microsoft.NET\Framework64\v2.0.50727 (if you are on 32 bit, get this dll from 64 bit machine)
- Select InstallUtilLib.dll
- Click the Open button
- Click the OK button
To ignore modifying msi every time, write post build script to web setup project in visual studio. Follow below steps:
1. Create vbscript file as .vbs for script below
|
Option Explicit Dim releasemode : releasemode = Wscript.Arguments(1) If releasemode <> "Release64" THEN WScript.Echo "You execute a script, you need to change MSI for compatible 64 bit machine." Const msiOpenDatabaseModeTransact = 1 rem path to the 64bit version of InstallUtilLib.dll Dim installer : Set installer = Wscript.CreateObject("WindowsInstaller.Installer") Dim sqlQuery : sqlQuery = "SELECT `Name`, `Data` FROM Binary" Dim database Dim record : Set record = installer.CreateRecord(2) record.SetStream 2, INSTALL_UTIL_LIB_PATH view.Modify msiViewModifyAssign, record Set view = Nothing |
2. Write post build script : wscript.exe "[Path]\Setup_PostBuildEvent_x64.vbs" "$(BuiltOuputPath)" "$(Configuration)"
Note: Create new configuration for 64 bit machine from configuration manager.
Outstanding example. Exactly what I’ve been looking for. Thank you!