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

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,

  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.NET\Framework64\v2.0.50727 (if you are on 32 bit, get this dll from 64 bit machine)
  6. Select InstallUtilLib.dll
  7. Click the Open button
  8. 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
rem ———————————————————–
rem Setup_PostBuildEvent_x64.vbs
rem
rem Patch an msi with the 64bit version of InstallUtilLib.dll
rem to allow x64 built managed CustomActions.
rem ———————————————————–   

Dim releasemode : releasemode = Wscript.Arguments(1)

If releasemode <> "Release64" THEN
    WScript.Echo "You execute a script for 32 bit."
    WScript.quit 0
End If

WScript.Echo "You execute a script, you need to change MSI for compatible 64 bit machine."

Const msiOpenDatabaseModeTransact = 1
Const msiViewModifyAssign         = 3

rem path to the 64bit version of InstallUtilLib.dll
Const INSTALL_UTIL_LIB_PATH = "[Path]\InstallUtilLib.dll"

Dim installer : Set installer = Wscript.CreateObject("WindowsInstaller.Installer")

Dim sqlQuery : sqlQuery = "SELECT `Name`, `Data` FROM Binary"

Dim database
Set database = installer.OpenDatabase(Wscript.Arguments(0), msiOpenDatabaseModeTransact)
Dim view : Set view = database.OpenView(sqlQuery)

Dim record : Set record = installer.CreateRecord(2)
record.StringData(1) = "InstallUtil"
view.Execute record

record.SetStream 2, INSTALL_UTIL_LIB_PATH

view.Modify msiViewModifyAssign, record
database.Commit

Set view = Nothing
Set database = 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.

Source: http://blogs.msdn.com/b/heaths/archive/2006/02/01/64-bit-managed-custom-actions-with-visual-studio.aspx

Advertisement

One Response to 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

  1. Loren Cress says:

    Outstanding example. Exactly what I’ve been looking for. Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.