title: Simple WiX Custom Action in Custom UI Ends Prematurely
body: <p>Using Visual Studio 2012, WiX 3.7, when I try to execute a <strong>Custom Action</strong> in my <strong>Custom UI</strong> to validate a product key input, the installer simply goes to a "Setup Wizard ended prematurely" dialog and forces you to Exit (there is no error message thrown) no matter what is entered into the product key input.</p>
  
  <p>The guide I was following is <a href="http://www.schiffhauer.com/downloads/WiX-Walkthrough.pdf">http://www.schiffhauer.com/downloads/WiX-Walkthrough.pdf</a></p>
  
  <p>I've ran the .msi with logging enabled and I still don't see what is wrong. I've included below what I think is all the pertinent information, if you want more please let me know. <del>I'm not sure how to debug this in Visual Studio, the <code>System.Diagnostics.Debugger.Launch();</code> in the CustomAction doesn't seem to do anything.</del> I was able to get Debugging to work via <a href="http://www.davidmoore.info/2010/06/28/how-to-debug-a-windows-installer-custom-action/">http://www.davidmoore.info/2010/06/28/how-to-debug-a-windows-installer-custom-action/</a> but even when setting breakpoints VS just says <code>msiexec.exe has triggered a breakpoint</code> and <code>Source Not Available</code>.</p>
  
  <p>UI.wxs:</p>
  
  <pre><code>&lt;Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="Next"&gt;
    &lt;!-- ValidateProductID using CustomAction 'LicenseCheckAction' --&gt;
    &lt;Publish Event="DoAction" Value="LicenseCheckAction"&gt;1&lt;/Publish&gt;
    &lt;Publish Event="SpawnDialog" Value="InvalidPidDlg"&gt;PIDACCEPTED = "0"&lt;/Publish&gt;
    &lt;Publish Event="NewDialog" Value="InstallDirDlg"&gt;PIDACCEPTED = "1"&lt;/Publish&gt;
  &lt;/Control&gt;
  &lt;Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel"&gt;
    &lt;Publish Event="SpawnDialog" Value="CancelDlg"&gt;1&lt;/Publish&gt;
  &lt;/Control&gt;
  </code></pre>
  
  <p>Product.wxs:</p>
  
  <pre><code>&lt;Binary Id="LicenseCheckDLL" SourceFile="..\LicenseCheck\bin\$(var.MyProj.Configuration)\LicenseCheck.CA.dll" /&gt;
  &lt;CustomAction Id="LicenseCheckAction" BinaryKey="LicenseCheckDLL" DllEntry="LicenseCheck" /&gt;
  &lt;UIRef Id="$(var.ProductName)_UI" /&gt;
  </code></pre>
  
  <p>CustomAction:</p>
  
  <pre><code>public class CustomActions
  {
      [CustomAction]
      public static ActionResult LicenseCheck(Session session)
      {
          try
          {
              session.Log("Begin LicenseCheck");
              string Pid = session["PIDKEY"];
              session["PIDACCEPTED"] = Pid.StartsWith("1") ? "1" : "0";
          }
          catch (Exception ex)
          {
              session.Log("ERROR Caught in custom action: {0}", ex.ToString());
              return ActionResult.Failure;
          }
          return ActionResult.Success;
      }
  }
  </code></pre>
  
  <p>Log:</p>
  
  <pre><code>Action 10:57:04: LicenseAgreementDlg. Dialog created
  MSI (c) (A4:64) [10:57:05:863]: PROPERTY CHANGE: Adding LicenseAccepted property. Its value is '1'.
  Action 10:57:06: LicenseKeyDlg. Dialog created
  MSI (c) (A4:64) [10:57:07:017]: PROPERTY CHANGE: Adding PIDKEY property. Its value is '**********'.
  MSI (c) (A4:64) [10:57:21:142]: PROPERTY CHANGE: Modifying PIDKEY property. Its current value is '**********'. Its new value: '**********'.
  MSI (c) (A4:64) [10:57:21:215]: Doing action: LicenseCheckAction
  Action 10:57:21: LicenseCheckAction. 
  Action start 10:57:21: LicenseCheckAction.
  MSI (c) (A4:64) [10:57:21:239]: Creating MSIHANDLE (1) of type 790542 for thread 6756
  MSI (c) (A4:EC) [10:57:21:240]: Invoking remote custom action. DLL: C:\Users\dirt\AppData\Local\Temp\MSI2AEF.tmp, Entrypoint: LicenseCheck
  MSI (c) (A4:58) [10:57:21:241]: Cloaking enabled.
  MSI (c) (A4:58) [10:57:21:241]: Attempting to enable all disabled privileges before calling Install on Server
  MSI (c) (A4:58) [10:57:21:241]: Connected to service for CA interface.
  MSI (c) (A4!A4) [10:57:21:280]: Creating MSIHANDLE (2) of type 790531 for thread 9892
  MSI (c) (A4!A4) [10:57:21:280]: Closing MSIHANDLE (2) of type 790531 for thread 9892
  MSI (c) (A4!A4) [10:57:21:300]: Creating MSIHANDLE (3) of type 790531 for thread 9892
  MSI (c) (A4!A4) [10:57:21:300]: Closing MSIHANDLE (3) of type 790531 for thread 9892
  MSI (c) (A4!A4) [10:57:21:331]: Creating MSIHANDLE (4) of type 790531 for thread 9892
  MSI (c) (A4!A4) [10:57:21:333]: Closing MSIHANDLE (4) of type 790531 for thread 9892
  MSI (c) (A4!A4) [10:57:21:335]: Creating MSIHANDLE (5) of type 790531 for thread 9892
  MSI (c) (A4!A4) [10:57:21:335]: Closing MSIHANDLE (5) of type 790531 for thread 9892
  MSI (c) (A4!A4) [10:57:21:336]: Creating MSIHANDLE (6) of type 790531 for thread 9892
  MSI (c) (A4!A4) [10:57:21:337]: Closing MSIHANDLE (6) of type 790531 for thread 9892
  MSI (c) (A4:EC) [10:57:21:341]: Closing MSIHANDLE (1) of type 790542 for thread 6756
  Action ended 10:57:21: LicenseCheckAction. Return value 3.
  DEBUG: Error 2896:  Executing action LicenseCheckActionfailed.
  The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: LicenseCheckAction, , 
  Action ended 10:57:21: WelcomeDlg. Return value 3.
  MSI (c) (A4:50) [10:57:21:343]: Doing action: FatalError
  Action 10:57:21: FatalError. 
  Action start 10:57:21: FatalError.
  Action 10:57:21: FatalError. Dialog created
  Action ended 10:57:23: FatalError. Return value 2.
  Action ended 10:57:23: INSTALL. Return value 3.
  MSI (c) (A4:50) [10:57:23:556]: Destroying RemoteAPI object.
  MSI (c) (A4:58) [10:57:23:556]: Custom Action Manager thread ending.
  </code></pre>