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

Invoke-RestMethod started to fail in v6-beta.9 on a Windows 7 machine #5242

Closed
nightroman opened this issue Oct 26, 2017 · 4 comments · Fixed by #5256
Closed

Invoke-RestMethod started to fail in v6-beta.9 on a Windows 7 machine #5242

nightroman opened this issue Oct 26, 2017 · 4 comments · Fixed by #5256
Assignees
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-Fixed The issue is fixed. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Milestone

Comments

@nightroman
Copy link

nightroman commented Oct 26, 2017

  • This issue happens on a Windows 7 machine. All works fine on Windows 8.1 and 10.
  • This issue is new in v6-beta.9. All was fine in previous betas and is fine in v5.

Problem case:

Invoke-RestMethod https://api.github.com/users/nightroman/repos

Expected result:

The command returns the requested data.

Actual result:

The command fails:

Invoke-RestMethod : Version string portion was too short or too long.
At line:1 char:1
+ Invoke-RestMethod https://api.github.com/users/nightroman/repos
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Some info about the inner exception:

PS> $error.Exception.ToString()
System.ArgumentException: Version string portion was too short or too long.
   at System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
   at System.Version.TryParseVersion(String version, VersionResult& result)
   at System.Version.Parse(String input)
   at System.Version..ctor(String version)
   at Microsoft.PowerShell.Commands.PSUserAgent.get_PlatformName()
   at Microsoft.PowerShell.Commands.PSUserAgent.get_UserAgent()
   at Microsoft.PowerShell.Commands.WebRequestSession..ctor()
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.PrepareSession()
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
   at System.Management.Automation.Cmdlet.DoProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()

Environment:

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta.9
PSEdition                      Core
GitCommitId                    v6.0.0-beta.9
OS                             Microsoft Windows 6.1.7601 S
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@markekraus
Copy link
Contributor

It looks like this is related to the change in #4937

@markekraus markekraus added WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module Issue-Bug Issue has been identified as a bug in the product labels Oct 26, 2017
@SteveL-MSFT SteveL-MSFT added this to the 6.0.0-HighPriority milestone Oct 26, 2017
@thezim
Copy link
Contributor

thezim commented Oct 26, 2017

Note that most web server can and should limit length of individual headers lengths it accepts, I’ve had to do this to adhere to best practices and organizational security requirements on my servers. Usually the request is returned as a 400 series http status code. This might be the case in this instance. For Windows 7 it might be crossing that threshold. If that is the case then the workaround would be to explicitly set the user agent or default the parameter.

@markekraus
Copy link
Contributor

markekraus commented Oct 26, 2017

@thezim this is occurring during the generation of the User-Agent header before it is even sent to the remote server. This is related to a change where we made the User-Agent platform aware instead of always reporting Win NT. The underlying .NET would complain on a non-compliant User-Agent (at least for the default generated User-Agent).

@markekraus
Copy link
Contributor

The change in #4937 is using System.Runtime.InteropServices.RuntimeInformation.OSDescription which on Windows 7 produces something like Microsoft Windows 6.1.7601 S and on Windows 10 Microsoft Windows 10.0.15063. The offending code is here:

string versionText = OS.Substring(OS.LastIndexOf(" ") +1);
Version windowsPlatformversion = new Version(versionText);

Since windows 7 is using an extra space after the version number its capturing S as the substring and then failing to parse that as a Version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-Fixed The issue is fixed. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants