How to access session custom action data (properties) during install and uninstall in Wix?

Can you please tell me what is wrong with the following code? I am able to access the custom action data during install and I add their values to session custom action collection. However, during uninstall I the value pairs are not in the collection.

public class CustomActions
    //This action is only called during application install
    public static ActionResult CreateToolbar(Session session)       
        //This works fine the value is properly sent from wix script
        //The variable toolbarName has the expected value
        string toolbarName = session["VSTOCustomAction_ToolbarName"];

        //Save the value for uninstaller
        session.CustomActionData.Add("VSTOCustomAction_ToolbarName", toolbarName);

    //This action is only called during application uninstall
    public static ActionResult RemoveToolbar(Session session)
        //Get the toolbar name and remove it
        //Why does the following call return null?
        string toolbarName = session.CustomActionData["VSTOCustomAction_ToolbarName"];          

Below is the WIX part that calls the above custom action.

<!-- Include the VSTO Custom action  -->
<Binary Id="VSTOCustomAction" SourceFile="CustomAction.CA.dll"/>
<CustomAction Id="CreateToolbar" BinaryKey="VSTOCustomAction" DllEntry="CreateToolbar" Execute="immediate"/>
<CustomAction Id="RemoveToolbar" BinaryKey="VSTOCustomAction" DllEntry="RemoveToolbar" Execute="immediate"/>
<CustomAction Id="PropertyAssign_ToolbarName" Property="VSTOCustomAction_ToolbarName" Value="MyToolBarName"/>
<!-- Modify the install sequence to call our custom action -->
  <Custom Action="PropertyAssign_ToolbarName" Before="CreateToolbar"><![CDATA[(&ToolbarComponent = 3) AND NOT (!ToolbarComponent = 3)]]></Custom>
  <Custom Action="CreateToolbar" After="InstallFinalize"><![CDATA[(&ToolbarComponent = 3) AND NOT (!ToolbarComponent = 3)]]></Custom>
  <Custom Action="RemoveToolbar" After="InstallFinalize"><![CDATA[(&ToolbarComponent = 2) AND NOT (!ToolbarComponent = 2)]]></Custom>


MSI doesn't persist properties after an install. Read the following for a good solution.

"The WiX toolset's "Remember Property" pattern."

It seems that you are only creating the VSTOCustomAction_ToolbarName property when installing the ToolbarComponent, so when you try to uninstall, the VSTOCustomAction_ToolbarName property is never created, nor set.

One way to solve this problem could be saving the Toolbar Name on a Windows registry key instead of creating a property to contain this value, so you can read it while trying to uninstall your product.

Need Your Help

Passing variables to awk code block in org-mode

emacs awk org-mode org-babel

I have a small code block, in Org-Babel, that should depend on some parameters. I've written my code in awk but I didn't succeed using the parameters in my code.

Trouble with mysqldump when backing up db as xml

php mysql xml shell mysqldump

I'm trying to backup one of my databases with mysqldump and I'm trying to export it to an xml file which already exists. Here is what I have: