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

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

Closed
Arnavion opened this issue May 3, 2018 · 3 comments
Labels
bug

Comments

@Arnavion
Copy link

@Arnavion Arnavion commented May 3, 2018

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

f3f559c#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.

@Arnavion

This comment has been minimized.

Copy link
Author

@Arnavion Arnavion commented May 3, 2018

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

@rasa rasa added the bug label May 3, 2018
@Arnavion

This comment has been minimized.

Copy link
Author

@Arnavion Arnavion commented Jun 20, 2018

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 PowerShell/PowerShell#6561 )

@r15ch13

This comment has been minimized.

Copy link
Collaborator

@r15ch13 r15ch13 commented Aug 7, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.