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

Rob Mensching rob at firegiant.com
Tue Mar 26 20:11:48 PDT 2019

The stack trace seems to show the custom action trying to set a property:

   at Microsoft.Deployment.WindowsInstaller.Session.set_Item(String
property, String value)

PS: don't write your custom action like this, add temporary rows to tables instead.

 Short replies here. Complete answers over there: http://www.firegiant.com/

-----Original Message-----
From: wix-users <wix-users-bounces at lists.wixtoolset.org> On Behalf Of Justin Cox via wix-users
Sent: Tuesday, March 26, 2019 5:38 PM
To: WiX Toolset Users Mailing List (wix-users at lists.wixtoolset.org) <wix-users at lists.wixtoolset.org>
Cc: Justin Cox <cox.justin.a at gmail.com>
Subject: [wix-users] Can't Access CustomData during uninstall

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 = folderlist.Split('|').ToList();
                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 'FolderList=C:\inetpub\wwwroot\XXXXXClientInterface\'.

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 = session.CustomActionData["FolderList"];"

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

WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/

More information about the wix-users mailing list