Exception from System.IO.Directory.Delete is not caught in customaction (msi generated with wix toolset)
Occured on .NET Framework 4.7.2 Windows 7 started as administrator.
Logfile from call of customaction:
MSI (s) (A0:D8) [08:31:39:027]: Executing op: ActionStart(Name=CacheCustomActions.DeleteOldInstallationFolders,,) MSI (s) (A0:D8) [08:31:39:027]: Executing op: CustomActionSchedule(Action=CacheCustomActions.DeleteOldInstallationFolders,ActionType=1025,Source=BinaryData,Target=DeleteOldInstallationFolders,CustomActionData=XXXDIR=C:\XXX\;) MSI (s) (A0:AC) [08:31:39:028]: Invoking remote custom action. DLL: C:\Windows\Installer\MSI7B8A.tmp, Entrypoint: DeleteOldInstallationFolders SFXCA: Extracting custom action to temporary directory: C:\Windows\Installer\MSI7B8A.tmp-\ SFXCA: Binding to CLR version v4.0.30319 Calling custom action CustomActions!CustomActions.CustomActions.DeleteOldInstallationFolders ***** Begin DeleteOldInstallationFolders ***** Deleting folder: C:\XXX\temp ***** Deleting folder: C:\XXX\temp2 CustomAction CacheCustomActions.DeleteOldInstallationFolders returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
try
{
session.LogWithTime($"Deleting directory {directory}");
Directory.Delete(directory, true);
}
catch (Exception e)
{
session.LogWithTime($"Failed to delete directory {directory}");
}
Expected: Directory is deleted or exception is thrown Actual: Custom Action exists with error code 1603.
Wxs Files look like this but I don't think that there is a problem, everything works fine on hundreds of computers, it was only one machine where the error occured:
<CustomAction Id="PrepareArgumentsForDeferredCall.DeleteOldInstallationFolders" Property="CacheCustomActions.DeleteOldInstallationFolders" Value="XXXDIR=[XXXDIR];ISEXPERTMODEENABLED=[ISEXPERTMODEENABLED]" Execute="immediate" />
[...]
<CustomAction Id="CacheCustomActions.DeleteOldInstallationFolders" BinaryKey="CustomActionBinary" DllEntry="DeleteOldInstallationFolders" Execute="deferred" Return="check"/>
[...]
<Custom Action="PrepareArgumentsForDeferredCall.DeleteOldInstallationFolders" After="CostFinalize" />
[..]
<Custom Action="CacheCustomActions.DeleteOldInstallationFolders" After="InstallInitialize">NOT REMOVE AND NOT PATCH AND NOT REINSTALL</Custom>