Collins
Posts: 138
Joined: Wed Oct 12, 2016 2:57 pm

PowerShell Custom Action Fails Install After Upgrade To 17.1.1

Fri May 29, 2020 2:27 pm

Hello,

I have a PowerShell Inline custom action that I was using with version 16.9 and after I upgraded to 17.1.1, the install fails when it runs the custom action.

Code: Select all

$PATHS = @("HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
           "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
$SOFTWARE = "COMPANY BPR 2.0"

ForEach ($path in $PATHS) {
    $installed = Get-ChildItem -Path $path |
                 ForEach { Get-ItemProperty $_.PSPath } |
                 Where-Object { $_.DisplayName -match $SOFTWARE } |
                 Select-Object -Property DisplayVersion

    ForEach ($app in $installed) {
        Write-Host BPR Version Is "$($app.DisplayVersion)"
    }
}

AI_SetMsiProperty BPR_VERSION $app.DisplayVersion
Error message in log:
MSI (c) (38!D0) [08:56:58:066]: Closing MSIHANDLE (352) of type 790531 for thread 17360
MSI (c) (38!D0) [08:56:58:066]: PROPERTY CHANGE: Adding POWERSHELL_EXECUTION_LOG property. Its value is 'ERROR: Cannot bind argument to parameter 'value' because it is null.'.
CustomAction PowerShellGetBPRVersion returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
MSI (c) (38:90) [08:56:58:066]: Closing MSIHANDLE (348) of type 790542 for thread 22692
Action ended 8:56:58: PowerShellGetBPRVersion. Return value 3.
MSI (c) (38:A4) [08:56:58:066]: Doing action: FatalError


This is the error I get when testing it from within AI:
Return code: 574
Script output: "ERROR: Cannot bind argument to parameter 'value' because it is null."


When I remove "AI_SetMsiProperty BPR_VERSION $app.DisplayVersion" from the PS script, its fine and the install continues on launch.
The custom action was scheduled during dialog & install execution if it wasn't run during dialog stage, right after FindRelatedProducts.

For the time being, I unchecked the "Fail installation if custom action returns an error", but I have other projects that use AI_SetMsiProperty.

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: PowerShell Custom Action Fails Install After Upgrade To 17.1.1

Tue Jun 02, 2020 12:56 pm

Hello,

This is quite strange, indeed.

I have tested this and everything worked as expected on my end.
MSI (c) (38!D0) [08:56:58:066]: PROPERTY CHANGE: Adding POWERSHELL_EXECUTION_LOG property. Its value is 'ERROR: Cannot bind argument to parameter 'value' because it is null.'.
Here, could you please make sure that the "$app.DisplayVersion" has an actual value? You can do so by spawning a message box displaying its value.

You can add the following assembly at the begin of your script:

Code: Select all

Add-Type -AssemblyName PresentationFramework
and then spawn the message box with the following method:

Code: Select all

[System.Windows.MessageBox]::Show($app.DisplayName)
As per my understanding, the given error complains about the fact that the "$app.DisplayVersion" is null.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: PowerShell Custom Action Fails Install After Upgrade To 17.1.1

Tue Jun 02, 2020 1:08 pm

Hello,

As a followup to my latest thread:

I have further tested this and I was able to replicate the behavior.

The issue seems indeed to be related to the fact that the variable is null.

PSError.png
PSError.png (120.81KiB)Viewed 3885 times

As you can see, I am trying to set a property to a null variable, therefore the error is thrown.

Indeed, as you have mentioned, this did not seem to happen in version 16.9 of Advanced Installer.

As you could see, in the latest version of Advanced Installer, we have brought some modifications & improvements upon our support for PowerShell custom actions.

I believe the developer has included this exception in the error logic.

Upon further testing, I have noticed that this can be avoided if you simply initialize the variable to an empty string. For instance, instead of:

Code: Select all

AI_SetMsiProperty MY_VAR $var
we could have something like this:

Code: Select all

$var = ""

# your logic here

AI_SetMsiProperty MY_VAR $var
We basically initialize the variable with an empty string. If, in our logic, the variable is to be overwritten, it will be overwritten and then the value will be stored in the "MY_VAR" property.

NoError.png
NoError.png (115.98KiB)Viewed 3884 times


Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Collins
Posts: 138
Joined: Wed Oct 12, 2016 2:57 pm

Re: PowerShell Custom Action Fails Install After Upgrade To 17.1.1

Thu Jun 04, 2020 6:49 pm

Catalin wrote:
Tue Jun 02, 2020 1:08 pm

Upon further testing, I have noticed that this can be avoided if you simply initialize the variable to an empty string. For instance, instead of:

Code: Select all

AI_SetMsiProperty MY_VAR $var
we could have something like this:

Code: Select all

$var = ""

# your logic here

AI_SetMsiProperty MY_VAR $var
We basically initialize the variable with an empty string. If, in our logic, the variable is to be overwritten, it will be overwritten and then the value will be stored in the "MY_VAR" property.


NoError.png



Hope this helps.

Best regards,
Catalin
Thank you, that was helpful.

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: PowerShell Custom Action Fails Install After Upgrade To 17.1.1

Fri Jun 05, 2020 10:09 am

You are always welcome!

I am really glad the information was helpful for you.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”