I am following several sources/SO posts and even the Wix installer book and this is how I am currently setting two properties in an immediate custom action then trying to read it in a deferred action. However, its not working (fails and goes to roll back) and I keep getting System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. in my log.
Here is a portion of my .wxs file:
<!-- Custom Actions -->
<!-- Reference library for custom actions-->
<Binary Id="myCustomActions" SourceFile="$...something.CA.dll"/>
<!-- Set my properties that will be passed on to InsertPluginData as its a deferred CA and not able to read properties -->
<CustomAction
Id="CA_SetProperties"
BinaryKey="myCustomActions"
DllEntry="SetProperties"
Execute="immediate"
/>
<!-- This modifies the CSI File to insert the plugin into the interface -->
<!-- Eliminates the user having to do this manually -->
<CustomAction
Id="CA_InsertPluginData"
BinaryKey="myCustomActions"
DllEntry="InsertPluginData"
Execute="deferred"
Return="check"
/>
<!-- Custom Actions Sequence -->
<InstallExecuteSequence>
<Custom Action="CA_SetProperties" After="InstallInitialize" />
<Custom Action="CA_InsertPluginData" Before="InstallFinalize"/>
</InstallExecuteSequence>
My CustomActions.cs:
[CustomAction]
public static ActionResult SetProperties(Session session)
{
session.Log("Begin SetProperties");
CustomActionData data = new CustomActionData();
data["Test"] = "1";
session["InsertPluginData"] = data.ToString();
session.Log("End SetProperties");
return ActionResult.Success;
}
[CustomAction]
public static ActionResult InsertPluginData(Session session)
{
session.Log("Begin InsertPluginData");
CustomActionData data = session.CustomActionData;
string property1 = data["Test"];
session.Log("Begin InsertPluginData: Test" + property1);
return ActionResult.Success;
}
To confirm my immediate action is happening I ran it with logging on:
Begin SetProperties
MSI (s) (D4!EC) [10:30:17:941]: PROPERTY CHANGE: Adding InsertPluginData property. Its value is 'Test=1'.
End SetProperties
I fixed it by modifying this line in SetProperties session["InsertPluginData"] = data.ToString(); to session["CA_InsertPluginData"] = data.ToString(). The key here is for the string inside the session to match the CustomAction Id set in .wxs file!