Scoop: Method invocation failed because [System.String] does not contain a method named 'ToLocalTime'

Created on 3 May 2018  路  3Comments  路  Source: lukesampson/scoop

Method invocation failed because [System.String] does not contain a method named 'ToLocalTime'.
At C:\Users\Arnavion\scoop\apps\scoop\current\lib\core.ps1:499 char:12
+     return $last_update.ToLocalTime()
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

https://github.com/lukesampson/scoop/commit/f3f559c460406689dab2375310fb1026e2be58bd#diff-f0957a994e6c95d903caeb55bf700101R494

Before this change the String from scoop config lastupdate would get converted to DateTime using Get-Date. After that change it just keeps the string as-is, and you can't call .ToLocalTime on a String.


Seems to be because on PS Core, scoop config lastupdate does return a DateTime, but on PS 5 it returns a String ?

Core:

$ $PSVersionTable.PSVersion.ToString(); (scoop config lastupdate).GetType().FullName

6.0.1
System.DateTime

5.0:

$ $PSVersionTable.PSVersion.ToString(); (scoop config lastupdate).GetType().FullName

5.0.10586.117
System.String

gcm scoop confirms it's the same C:\Users\Arnavion\scoop\shims\scoop.ps1 in both cases.

bug

Most helpful comment

Okay, ConvertFrom-Json is the reason.

Core:

$ echo '"2018-05-02T23:03:22.5046021-07:00"' | ConvertFrom-Json | % GetType | % FullName

System.DateTime

$ gcm ConvertFrom-Json | % Module | % Path

C:\program files\powershell\6.0.1\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1

5.0:

$ echo '"2018-05-02T23:03:22.5046021-07:00"' | ConvertFrom-Json | % GetType | % FullName

System.String

$ gcm ConvertFrom-Json | % Module | % Path

C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1

You probably want to restore the Get-Date call for scoop config lastupdate

All 3 comments

Okay, ConvertFrom-Json is the reason.

Core:

$ echo '"2018-05-02T23:03:22.5046021-07:00"' | ConvertFrom-Json | % GetType | % FullName

System.DateTime

$ gcm ConvertFrom-Json | % Module | % Path

C:\program files\powershell\6.0.1\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1

5.0:

$ echo '"2018-05-02T23:03:22.5046021-07:00"' | ConvertFrom-Json | % GetType | % FullName

System.String

$ gcm ConvertFrom-Json | % Module | % Path

C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1

You probably want to restore the Get-Date call for scoop config lastupdate

I should add: this happens if you use pwsh to run scoop update and then use powershell to run it. Running under pwsh saves the lastupdate value in ~/.scoop to the NewtonSoft.Json format used by pwsh's ConvertTo-Json, which powershell's ConvertFrom-Json can't parse.

(I had to switch to powershell because some scoop packages can't be installed with pwsh, because of https://github.com/PowerShell/PowerShell/issues/6561 )

Fixed it by using the round-trip date/time pattern o which is used by pwsh.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SinisterBlade picture SinisterBlade  路  3Comments

borekb picture borekb  路  3Comments

nitrocode picture nitrocode  路  3Comments

muhlpachr picture muhlpachr  路  3Comments

klauern picture klauern  路  3Comments