Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MethodInvocationException when running winget-upgrade.ps1 with PowerShell 7.2.1 #6

Closed
derkrasseleo opened this issue Feb 20, 2022 · 13 comments

Comments

@derkrasseleo
Copy link
Contributor

derkrasseleo commented Feb 20, 2022

I installed the current version (1.4.1) and ran winget-upgrade.ps1 from the WingetAutoUpdate directory with PowerShell 7.2.1 and it didn't work. I did this because after installation, there was no sign of it running.

Don't know what all of this means, but I don't think that's supposed to happen:

23:10:58 - No new update.
23:10:58 - End of process!
PS C:\ProgramData\Winget-AutoUpdate> .\winget-upgrade.ps1
##################################################
#     CHECK FOR APP UPDATES - 20.02.2022
##################################################
23:15:30 - Notification Langugage : en-US
23:15:30 - Checking internet connection...
23:15:30 - Connected !
23:15:30 - Checking available updates...
MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:213
Line |
 213 |              $software.Id = $line.Substring($idStart, $versionStart -  …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:214
Line |
 214 |              $software.Version = $line.Substring($versionStart, $avail …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:215
Line |
 215 |              $software.AvailableVersion = $line.Substring($availableSt …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "StartIndex cannot be less than zero. (Parameter 'startIndex')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:213
Line |
 213 |              $software.Id = $line.Substring($idStart, $versionStart -  …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:214
Line |
 214 |              $software.Version = $line.Substring($versionStart, $avail …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:215
Line |
 215 |              $software.AvailableVersion = $line.Substring($availableSt …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "StartIndex cannot be less than zero. (Parameter 'startIndex')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:213
Line |
 213 |              $software.Id = $line.Substring($idStart, $versionStart -  …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:214
Line |
 214 |              $software.Version = $line.Substring($versionStart, $avail …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:215
Line |
 215 |              $software.AvailableVersion = $line.Substring($availableSt …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "StartIndex cannot be less than zero. (Parameter 'startIndex')"

23:15:36 - No new update.
23:15:36 - End of process!

Running it with "normal" PowerShell:

PS C:\ProgramData\Winget-AutoUpdate> .\winget-upgrade.ps1
##################################################
#     CHECK FOR APP UPDATES - 20.02.2022
##################################################
23:17:16 - Notification Langugage : en-US
23:17:16 - Checking internet connection...
23:17:17 - Connected !
23:17:17 - Checking available updates...
The value "Unknown" cannot be converted to the type "System.Version". Error: "The version string part was either too short or too long."
In C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:217 Zeichen:17
+ ...         if ([version]$software.AvailableVersion -gt [version]$softwar ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastParseTargetInvocation

The value "Unknown" cannot be converted to the type "System.Version". Error: "The version string part was either too short or too long."
In C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:217 Zeichen:17
+ ...         if ([version]$software.AvailableVersion -gt [version]$softwar ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastParseTargetInvocation

23:17:19 - No new update.
23:17:19 - End of process!
@Romanitho
Copy link
Owner

what is the current state of available updates by running this in cmd please:
winget upgrade

@derkrasseleo
Copy link
Contributor Author

PS C:\Users\leoch> winget upgrade
Name           Id                    Version Available   Source
---------------------------------------------------------------
FL Studio      ImageLine.FLStudio    Unknown 20.9.0.2748 winget
Product Portal iZotope.ProductPortal Unknown 1.4.3       winget
2 upgrades available.

After running winget-upgrade-ps1 again, I still get the same error messages. Also, shouldn't it run on user log on? I mean, there should at least be a notification that says "no updates found" or something like that.

@Romanitho
Copy link
Owner

Romanitho commented Feb 21, 2022

In fact, Winget cannot detect the current version of certain apps (More info here) This is the case for these 2 apps.
That's why it says that you have 2 updates.
With Winget-AutoUpdate, we made the choice to skip to manage theses apps to be sure we don't have "spammed" notification everyday.
Eventually, we can update our scripts to avoid "errors" during update detections.

What you can try, is to install an old 7-zip for example, and restart Winget-AutoUpdate to see if it works well when a "correct" apps has to be updated.

@derkrasseleo
Copy link
Contributor Author

In fact, Winget cannot detect the current version of certain apps (More info here) This is the case for these 2 apps. That's why it says that you have 2 updates. With Winget-AutoUpdate, we made the choice to skip to manage theses apps to be sure we don't have "spammed" notification everyday. Eventually, we can update our scripts to avoid "errors" during update detections.

What you can try, is to install an old 7-zip for example, and restart Winget-AutoUpdate to see if it works well when a "correct" apps has to be updated.

Thanks for the clarification! I already knew that, but when I run winget upgrade, it upgrades these apps regardless. But I think the way your script does it is the right behavior, if the errors are handled properly.
I tried your suggestion but it still doesn't work :(

@derkrasseleo
Copy link
Contributor Author

derkrasseleo commented Feb 21, 2022

I tried to reinstall it and now it tries to upgrade but fails:

image

edit: The log is not very helpful

##################################################
#     CHECK FOR APP UPDATES - 21.02.2022
##################################################
11:36:49 - Notification Langugage : en-US
11:36:49 - Checking internet connection...
11:36:50 - Connected !
11:36:50 - Checking available updates...
Available update : 7-Zip. Current version : 16.04. Available version : 21.07.
11:36:52 - Updating 7-Zip from 16.04 to 21.07...
11:36:56 - ------ Winget - 7-Zip Upgrade Starts ------
11:36:58 - ----- Winget - 7-Zip Upgrade Finished -----
11:37:02 - 7-Zip update failed.
11:37:06 - No new update.
11:37:06 - End of process!

@Romanitho
Copy link
Owner

What do you have if you run the script from powershell ?

@derkrasseleo
Copy link
Contributor Author

PS C:\ProgramData\Winget-AutoUpdate> .\winget-upgrade.ps1
##################################################
#     CHECK FOR APP UPDATES - 21.02.2022
##################################################
11:47:42 - Notification Langugage : en-US
11:47:42 - Checking internet connection...
11:47:42 - Connected !
11:47:42 - Checking available updates...
MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:213
Line |
 213 |              $software.Id = $line.Substring($idStart, $versionStart -  …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter
     | 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:214
Line |
 214 |              $software.Version = $line.Substring($versionStart, $avail …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter
     | 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:215
Line |
 215 |              $software.AvailableVersion = $line.Substring($availableSt …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "StartIndex cannot be less than zero. (Parameter
     | 'startIndex')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:213
Line |
 213 |              $software.Id = $line.Substring($idStart, $versionStart -  …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter
     | 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:214
Line |
 214 |              $software.Version = $line.Substring($versionStart, $avail …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter
     | 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:215
Line |
 215 |              $software.AvailableVersion = $line.Substring($availableSt …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "StartIndex cannot be less than zero. (Parameter
     | 'startIndex')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:213
Line |
 213 |              $software.Id = $line.Substring($idStart, $versionStart -  …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter
     | 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:214
Line |
 214 |              $software.Version = $line.Substring($versionStart, $avail …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter
     | 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:215
Line |
 215 |              $software.AvailableVersion = $line.Substring($availableSt …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "StartIndex cannot be less than zero. (Parameter
     | 'startIndex')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:213
Line |
 213 |              $software.Id = $line.Substring($idStart, $versionStart -  …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter
     | 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:214
Line |
 214 |              $software.Version = $line.Substring($versionStart, $avail …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero. (Parameter
     | 'length')"

MethodInvocationException: C:\ProgramData\Winget-AutoUpdate\winget-upgrade.ps1:215
Line |
 215 |              $software.AvailableVersion = $line.Substring($availableSt …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Substring" with "2" argument(s): "StartIndex cannot be less than zero. (Parameter
     | 'startIndex')"

11:47:46 - No new update.
11:47:46 - End of process!

@Romanitho
Copy link
Owner

I'll try to install an "unknown" version app to see how it behaves on my machine.

@derkrasseleo
Copy link
Contributor Author

I uninstalled both packages with unknown version with only 7zip left and I still get the same error.

@Romanitho
Copy link
Owner

I have installed iZotope.ProductPortal and an old 7zip and it worked for me and properly skipped "unknown" app :

##################################################
CHECK FOR APP UPDATES - 21/02/2022
##################################################
12:13:34 - Notification Langugage : fr-FR
12:13:34 - Checking internet connection...
12:13:34 - Connected !
12:13:34 - Checking available updates...
Available update : 7-Zip. Current version : 19.00. Available version : 21.07.
12:13:44 - Updating 7-Zip from 19.00 to 21.07...
12:13:49 - ------ Winget - 7-Zip Upgrade Starts ------
12:13:54 - ----- Winget - 7-Zip Upgrade Finished -----
12:13:57 - 7-Zip updated to 21.07 !
12:14:01 - 1 apps updated ! No more update.
12:14:01 - End of process!

@derkrasseleo
Copy link
Contributor Author

Oh, I think the problem with 7zip was that I had the newest version AND V19 installed and it thought the newest update was already installed so it didn't upgrade. oops

@derkrasseleo
Copy link
Contributor Author

Works fine now, uninstsalled all versions of 7zip. Installed an old version, restarted and the notification showed up and succesfully upgraded 7zip! Thank you for your effort!

@Romanitho
Copy link
Owner

Working on an update to better handle "unknown" apps ;)

Romanitho pushed a commit that referenced this issue Sep 1, 2024
…gmail-com-patch-2

Update Test-ModsPath.ps1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants