[wix-users] Can't Access CustomData during uninstall

Justin Cox cox.justin.a at gmail.com
Tue Mar 26 17:37:50 PDT 2019

I have custom scripts to backup folders during an install, rollback, and
uninstall.  they all work except for the uninstall.
I set the value:
  <CustomAction Id="SetFolderValuesUninstall" Property="UninstallFolders"

I execute the command:
  <CustomAction Id="UninstallFolders" BinaryKey="XXXXXShared.CA.dll"
DllEntry="UninstallFolders" Return="check" Execute="deferred" />

My C# code is:
        public static ActionResult UninstallFolders(Session session)
            ActionResult ar = ActionResult.Success;
                string folderlist = session.CustomActionData["FolderList"];
                MessageBox.Show("FolderList = " + folderlist);
                List<string> foldersToDelete =
                ar = DeleteFolders(foldersToDelete, session);
                return ar;
            catch (Exception ex)
                ar = immediateErrorCatcher(ex, session);
                return ar;

Everything works fine during the install, but during the uninstall, it sets
the value correctly:

MSI (s) (60:04) [17:33:58:021]: PROPERTY CHANGE: Adding UninstallFolders
property. Its value is

Then, I get this error in verbose logging:
Calling custom action
Exception thrown by custom action:
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
   at Microsoft.Deployment.WindowsInstaller.Session.ValidateSessionAccess()
   at Microsoft.Deployment.WindowsInstaller.Session.set_Item(String
property, String value)
   at XXXXXShared.DPWixExtension.immediateErrorCatcher(Exception ex,
Session ses)
   at XXXXXShared.DPWixExtension.UninstallFolders(Session session)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object
arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
Object parameters, Object arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object parameters, CultureInfo culture)
sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)
CustomAction UninstallFolders returned actual error code 1603 (note this
may not be 100% accurate if translation happened inside sandbox)

the error is happening when I hite "string folderlist =

Is it possible to pass CustomActionData during an uninstall? Or has the
installer already thrown out those variables?

More information about the wix-users mailing list