title: WiX will not uninstall due to conditions in CustomAction
body: <p>I have an MSI that uses two CustomActions.  The first adds some stuff to the registry.  It runs every time <em>except</em> during uninstall.  The second removes a key from the registry to be run <em>only</em> during uninstall.</p>
  
  <p>Both CustomActions work fine, only now the MSI won't uninstall.</p>
  
  <p>By "it won't uninstall" I mean neither the file that is installed is deleted nor is the MSI removed from <em>Programs and Features</em> when uninstall is run.  The only thing is <em>does</em> do during uninstallation is the Custom Action that removes stuff from the registry.</p>
  
  <p>Note that the problem happens on a fresh Virtual Machine, so it's not like there are old versions with different GUIDs hanging around.  </p>
  
  <p>Also I don't think that there's a problem with the Features, as there's only one feature -- a textfile installation (it's a toy installation -- until I get this right it's not going in the real installer).</p>
  
  <p>Here is the <code>&lt;InstallExecutiveSequence&gt;</code> code from both Custom Actions.  The one where I put stuff into the registry, to be done every time <strong>except</strong> uninstall:</p>
  
  <pre><code>      &lt;InstallExecuteSequence&gt;
            &lt;Custom Action="CustomAction_CreateKey"
                    After="InstallInitialize"&gt;
            &lt;/Custom&gt;
        &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>And here is the same XML from where I delete from the registry, to be done <strong>only</strong> during uninstallation:</p>
  
  <pre><code>      &lt;InstallExecuteSequence&gt;
            &lt;Custom Action="CustomAction_DeleteKey"
                    After="InstallInitialize"&gt;
                (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
            &lt;/Custom&gt;
        &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>The uninstall logs aren't that helpful (at least, to me).  There's this:</p>
  
  <blockquote>
    <p>MSI (s) (BC:6C) [15:27:15:733]: Note: 1: 1725 </p>
    
    <p>MSI (s) (BC:6C) [15:27:15:733]: Note: 1: 2205 2:  3: Error </p>
    
    <p>MSI (s) (BC:6C) [15:27:15:733]: Note: 1: 2228 2:  3: Error 4: SELECT
    <code>Message</code> FROM <code>Error</code> WHERE <code>Error</code> = 1725 </p>
    
    <p>MSI (s) (BC:6C) [15:27:15:733]: Note: 1: 2205 2:  3: Error </p>
    
    <p>MSI (s) (BC:6C) [15:27:15:733]: Note: 1: 2228 2:  3: Error 4: SELECT
    <code>Message</code> FROM <code>Error</code> WHERE <code>Error</code> = 1709 </p>
    
    <p>MSI (s) (BC:6C) [15:27:15:733]: Product: CustomActionDeleteKeySetup --
    Removal failed.</p>
  </blockquote>
  
  <p>And this:</p>
  
  <blockquote>
    <p>Calling custom action DeleteKey!DeleteKey.CustomActions.DeleteTheKey</p>
    
    <p>Exception thrown by custom action:</p>
    
    <p>System.Reflection.TargetInvocationException: Exception has been thrown
    by the target of an invocation. --->
    Microsoft.Deployment.WindowsInstaller.InstallerException: Cannot
    access session details from a non-immediate custom action</p>
    
    <p>at
    Microsoft.Deployment.WindowsInstaller.Session.ValidateSessionAccess()</p>
    
    <p>at Microsoft.Deployment.WindowsInstaller.Session.set_Item(String
    property, String value)</p>
    
    <p>at DeleteKey.CustomActions.DeleteTheKey(Session session)<br>
    --- End of inner exception stack trace ---</p>
  </blockquote>
  
  <p>I'm not really sure what to look for in the log files.</p>
  
  <p>To sum up:  Custom Actions won't let me uninstall.  I'm pulling my hair out.</p>
  
  <p><strong><em>EDIT</em></strong></p>
  
  <p>I managed to get it working, but I don't know why.  It has something to do with the conditions.<br>
  The conditions were this:  when uninstalling <em>and only</em> uninstalling, I wanted to remove the key.  So -- as shown above -- here's the <code>&lt;InstallExecuteSequence&gt;</code> code:</p>
  
  <pre><code>  &lt;InstallExecuteSequence&gt;
        &lt;Custom Action="CustomAction_DeleteKey"
                After="InstallInitialize"&gt;
            (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
        &lt;/Custom&gt;
    &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>And then I wanted to create the key when doing everything <em>except</em> installing.  Before, I didn't have any conditions in the <code>&lt;InstallExecuteSequence&gt;</code> bit, but when I change it to this, it seems to work (that is, the custom actions work and it uninstalls):</p>
  
  <pre><code>  &lt;InstallExecuteSequence&gt;
        &lt;Custom Action="CustomAction_CreateKey"
                After="InstallInitialize"&gt;
            (NOT installed) OR (CHANGE) OR (REPAIR)
        &lt;/Custom&gt;
    &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>The question is:  why does it work?  Is it because earlier I was trying to run both Custom Actions during uninstallation?</p>