Tim Long
Tim Long

Reputation: 13778

Wix Custom Action Properties - Why doesn't this work?

I have the following Wix fragment, that invokes one of two custom actions depending on whether it is installing or uninstalling:

<?xml version="1.0" encoding="UTF-8" ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?include $(sys.CURRENTDIR)\Config.wxi?>
  <Fragment>
    <CustomAction Id="caSetPropertyForInstall" Property="caRegisterDriver" Value="DeviceId=$(var.DriverId);DeviceName=$(var.ChooserName)" />
    <CustomAction Id="caSetPropertyForUninstall" Property="caUnregisterDriver" Value="DeviceId=$(var.DriverId);DeviceName=$(var.ChooserName)" />
    <Binary Id="DriverRegCA" SourceFile="$(var.ASCOM.Wix.CustomActions.TargetDir)\$(var.ASCOM.Wix.CustomActions.TargetName).CA.dll" />
    <CustomAction Id="caRegisterDriver" BinaryKey="DriverRegCA" DllEntry="RegisterAscomDriver" Execute="deferred" Return="check" />
    <CustomAction Id="caUnregisterDriver" BinaryKey="DriverRegCA" DllEntry="UnregisterAscomDriver" Execute="immediate" Return="ignore" />
    <InstallExecuteSequence>
      <Custom Action="caSetPropertyForInstall" Before="caRegisterDriver" />
      <Custom Action="caSetPropertyForUninstall" Before="caUnregisterDriver" />

      <!-- Execute during install -->
      <Custom Action="caRegisterDriver" Before="InstallFinalize">NOT Installed</Custom>

      <!-- Execute during uninstall -->
      <Custom Action="caUnregisterDriver" Before="RemoveFiles">REMOVE ~= "ALL"</Custom>
    </InstallExecuteSequence>
  </Fragment>
</Wix>

The install CA works as expected. I set some properties in action Id=caSetpropertyForInstall, then action caRegisterDriver calls my C# managed custom action. The C# code queries the custom action properties like so:

var deviceId = session.CustomActionData["DeviceId"];
var deviceName = session.CustomActionData["DeviceName"];
Diagnostics.TraceInfo("Property DeviceId = [{0}]", deviceId);
Diagnostics.TraceInfo("Property DeviceName = [{0}]", deviceName);

the same C# method is used whether installing or uninstalling and, as already stated, this works during the install phase.

My problem is that during the uninstall phase, I receive an exception:

1 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ===== TiGra.Diagnostics Initialized: Default TraceLevel = Warning =====
2 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[Info]: Begin UnregisterAscomDriver custom action
3 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[Error]: Error while querying installer properties
4 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[Error]: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
5 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at System.ThrowHelper.ThrowKeyNotFoundException()
6 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
7 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at Microsoft.Deployment.WindowsInstaller.CustomActionData.get_Item(String key)
8 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at ASCOM.Wix.CustomActions.CustomActions.CreateAscomDeviceFromSessionProperties(IInstallerPropertyProvider session)
9 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe ASCOM.Wix.CustomActions.CustomActions[Error]: UnregisterAscomDriver failed: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
10 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at System.ThrowHelper.ThrowKeyNotFoundException()
11 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
12 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at Microsoft.Deployment.WindowsInstaller.CustomActionData.get_Item(String key)
13 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at ASCOM.Wix.CustomActions.CustomActions.CreateAscomDeviceFromSessionProperties(IInstallerPropertyProvider session)
14 23/01/2013 03:07:37 7120 C:\Windows\SysWOW64\rundll32.exe at ASCOM.Wix.CustomActions.CustomActions.UnregisterAscomDriver(Session session)

I can't see any difference in how I'm handling install and uninstall, so I'm puzzled as to why this is. Am I missing something obvious?

Upvotes: 0

Views: 3159

Answers (1)

Christopher Painter
Christopher Painter

Reputation: 55571

You have the custom action "caUnregisterDriver" scheduled for immediate execution rather then deferred execution. It won't have a CustomActionData property to deserialize into the collection.

BTW I also don't see rollback and commit custom actions so I'd be concerned about that also.

Upvotes: 3

Related Questions