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

dotnet tool restore throws ArgumentOutOfRangeException #34347

Closed
AristurtleDev opened this issue Jul 31, 2023 · 2 comments
Closed

dotnet tool restore throws ArgumentOutOfRangeException #34347

AristurtleDev opened this issue Jul 31, 2023 · 2 comments
Assignees
Milestone

Comments

@AristurtleDev
Copy link

AristurtleDev commented Jul 31, 2023

Describe the bug

When executing dotnet tool restore, it throws an exception stating ArgumentOutOfRangeException. This seems to only occur when the localization of the PC is set to any language that includes non-Latin characters, such as Thai.

This seems to be related to the same issue that happened with dotnet run in Issue #23004

The full exception is included below in the exception section.

To Reproduce

Set the localization language of your PC to any language that includes non-Latin characters. In this case, to reproduce the issue as we saw it, set the localization language to Thai.

After doing this, attempt to install any dotnet tool, for instance you can try dotnet tool install -g dotnet-ef and the error will occur.

As for the specific instance we noticed this issue, it was while helping a fellow community member diagnose the issue when creating a MonoGame project which includes several dotnet tools that needed to be restored. A basic sample of this project can be found at https://github.com/AristurtleDev/MonoGameSample

Before attempting use the sample project, ensure you have set your PC localization to anything that includes non-Latin characters such as Thai in our specific scenario.

Exceptions (if any)

 at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<<UseExceptionHandler>b__0>d.MoveNext()
System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex')
   at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex, Int32 length)
   at Microsoft.DotNet.Cli.RestoreCommandParser.RestoreRuntimeArgFunc(IEnumerable`1 rids)
   at Microsoft.DotNet.Cli.ForwardedOption`1.<>c__DisplayClass6_0.<SetForwardingFunction>b__0(T o)
   at System.Linq.Enumerable.SelectManySingleSelectorIteratSystem.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex')
   at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex, Int32 length)
   at Microsoft.DotNet.Cli.RestoreCommandParser.RestoreRuntimeArgFunc(IEnumerable`1 rids)
   at Microsoft.DotNet.Cli.ForwardedOption`1.<>c__DisplayClass6_0.<SetForwardingFunction>b__0(T o)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at Microsoft.DotNet.Tools.Restore.RestoreCommand.FromParseResult(ParseResult result, String msbuildPath, Boolean noLogo)
   at Microsoft.DotNetor`2.MoveNext()
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at Microsoft.DotNet.Tools.Restore.RestoreCommand.FromParseResult(ParseResult result, String msbuildPath, Boolean noLogo)
   at Microsoft.DotNet.Tools.Restore.RestoreCommand.Run(ParseResult parseResult)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.DotNet.Cli..Tools.Restore.RestoreCommand.Run(ParseResult parseResult)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.DotNet.Cli.Parser.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace fromParser.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__17_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<U previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__17_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<<UseExceptionHandler>b__0>d.MoveNext()seParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<<UseExceptionHandler>b__0>d.MoveNext()

Further technical details

  • Include the output of dotnet --info
$ dotnet --info
.NET SDK:
 Version:   7.0.306
 Commit:    f500069cb7

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.306\

Host:
  Version:      7.0.9
  Architecture: x64
  Commit:       8e9a17b221

.NET SDKs installed:
  7.0.306 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
    This occurs both in Visual Studio and VSCode when the dotnet tool restore command is executed on a windows PC where the language localization is one with non-Latin characters such as Thai.
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Tools untriaged Request triage from a team member labels Jul 31, 2023
@baronfel
Copy link
Member

baronfel commented Aug 8, 2023

We have bad RID parsing logic in two places in the CLI:

  • The 'common options' CLI parsers here
  • The 'restore' versions of these same forwarding functions here

The LastIndexOf call's aren't taking into account that the index could be -1 when not found, as in the case of the any RID.

We should fix these two, and to be honest the 'restore' versions of the option should be removed in favor of the CommonOptions version, like the other places that have a Runtime option have done.

@JL03-Yue
Copy link
Member

Closes as fixed in #35637

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants