title: Wix Custom Action Properties - Why doesn't this work?
body: <p>I have the following Wix fragment, that invokes one of two custom actions depending on whether it is installing or uninstalling:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"&gt;
    &lt;?include $(sys.CURRENTDIR)\Config.wxi?&gt;
    &lt;Fragment&gt;
      &lt;CustomAction Id="caSetPropertyForInstall" Property="caRegisterDriver" Value="DeviceId=$(var.DriverId);DeviceName=$(var.ChooserName)" /&gt;
      &lt;CustomAction Id="caSetPropertyForUninstall" Property="caUnregisterDriver" Value="DeviceId=$(var.DriverId);DeviceName=$(var.ChooserName)" /&gt;
      &lt;Binary Id="DriverRegCA" SourceFile="$(var.ASCOM.Wix.CustomActions.TargetDir)\$(var.ASCOM.Wix.CustomActions.TargetName).CA.dll" /&gt;
      &lt;CustomAction Id="caRegisterDriver" BinaryKey="DriverRegCA" DllEntry="RegisterAscomDriver" Execute="deferred" Return="check" /&gt;
      &lt;CustomAction Id="caUnregisterDriver" BinaryKey="DriverRegCA" DllEntry="UnregisterAscomDriver" Execute="immediate" Return="ignore" /&gt;
      &lt;InstallExecuteSequence&gt;
        &lt;Custom Action="caSetPropertyForInstall" Before="caRegisterDriver" /&gt;
        &lt;Custom Action="caSetPropertyForUninstall" Before="caUnregisterDriver" /&gt;
  
        &lt;!-- Execute during install --&gt;
        &lt;Custom Action="caRegisterDriver" Before="InstallFinalize"&gt;NOT Installed&lt;/Custom&gt;
  
        &lt;!-- Execute during uninstall --&gt;
        &lt;Custom Action="caUnregisterDriver" Before="RemoveFiles"&gt;REMOVE ~= "ALL"&lt;/Custom&gt;
      &lt;/InstallExecuteSequence&gt;
    &lt;/Fragment&gt;
  &lt;/Wix&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>var deviceId = session.CustomActionData["DeviceId"];
  var deviceName = session.CustomActionData["DeviceName"];
  Diagnostics.TraceInfo("Property DeviceId = [{0}]", deviceId);
  Diagnostics.TraceInfo("Property DeviceName = [{0}]", deviceName);
  </code></pre>
  
  <p>the same C# method is used whether installing or uninstalling and, as already stated, this works during the install phase.</p>
  
  <p>My problem is that during the uninstall phase, I receive an exception:</p>
  
  <pre>
  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)
  </pre>
  
  <p>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?</p>