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 run cannot run the project due to System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex') exception #23148

Open
timelessnesses opened this issue Dec 23, 2021 · 11 comments
Assignees
Labels
untriaged Request triage from a team member

Comments

@timelessnesses
Copy link

timelessnesses commented Dec 23, 2021

Describe the bug

dotnet run is unable to run the program due to error but dotnet build works fine.

To Reproduce

  1. Use dotnet 6.0
  2. Create a new dotnet project by do dotnet new console
  3. Write some random program (Here's mine)
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
  1. Run it by do dotnet run

Exceptions (if any)

System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex')
   at System.String.Substring(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex)
   at Microsoft.DotNet.Tools.Run.RunCommand.TryGetTargetArchitecture(String runtimeIdentifier, Nullable`1& targetArchitecture)
   at Microsoft.DotNet.Tools.Run.RunCommand.GetTargetCommand()
   at Microsoft.DotNet.Tools.Run.RunCommand.Execute()
   at Microsoft.DotNet.Tools.Run.RunCommand.Run(String[] args)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)

Further technical details

  • Include the output of dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   c:\program files\dotnet\sdk\6.0.100\

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  5.0.403 [c:\program files\dotnet\sdk]
  5.0.404 [c:\program files\dotnet\sdk]
  6.0.100 [c:\program files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.21 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.22 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.12 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.13 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.21 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.22 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.12 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.13 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.21 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.22 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.12 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.13 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
F:\Desktop\test>code -v
1.63.2
899d46d82c4c95423fb7e10e68eba52050e30ba3
x64
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Dec 23, 2021
@sakesun
Copy link

sakesun commented Jan 5, 2022

I've got the same problem on Raspberry Pi 400.

pi@raspberrypi:~/projects/ttb-ndis $ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.101
 Commit:    ef49f6213a

Runtime Environment:
 OS Name:     raspbian
 OS Version:  10
 OS Platform: Linux
 RID:         linux-arm
 Base Path:   /opt/dotnet/sdk/6.0.101/

Host (useful for support):
  Version: 6.0.1
  Commit:  3a25a7f1cc

.NET SDKs installed:
  6.0.101 [/opt/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.1 [/opt/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.1 [/opt/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
pi@raspberrypi:~/projects/ttb-ndis $ 

@KalleOlaviNiemitalo
Copy link

This is a duplicate of #23004, which seems to be triggered by a locale setting. On the Raspberry Pi, you might be able to work around the bug by changing the LANG or LC_COLLATE or LC_ALL environment variable.

@ponlawat-w
Copy link

Thanks @KalleOlaviNiemitalo, for Windows PowerShell I found the environment variable DOTNET_SYSTEM_GLOBALIZATION_INVARIANT being true solves the issue as current workaround.

> $env:DOTNET_SYSTEM_GLOBALIZATION_INVARIANT='True'
> dotnet run

@timelessnesses
Copy link
Author

Thanks @KalleOlaviNiemitalo, for Windows PowerShell I found the environment variable DOTNET_SYSTEM_GLOBALIZATION_INVARIANT being true solves the issue as current workaround.

> $env:DOTNET_SYSTEM_GLOBALIZATION_INVARIANT='True'
> dotnet run

sometimes dotnet program won't even run

@ponlawat-w
Copy link

ponlawat-w commented Jan 29, 2022

The environment variable DOTNET_SYSTEM_GLOBALIZATION_INVARIANT is not really working well for me, especially when my project contains string sorting because there won't be cultures data at all under this mode, according to this document: https://github.com/dotnet/runtime/blob/main/docs/design/features/globalization-invariant-mode.md

@sippagon
Copy link

I have the same problem as well. I solved it by changing Date format on windows to Christian era and Regional format to US I hope it will help you. refer https://docs.microsoft.com/en-us/dotnet/core/runtime-config/globalization

@Codingjames
Copy link

Thanks @KalleOlaviNiemitalo, for Windows PowerShell I found the environment variable DOTNET_SYSTEM_GLOBALIZATION_INVARIANT being true solves the issue as current workaround.

> $env:DOTNET_SYSTEM_GLOBALIZATION_INVARIANT='True'
> dotnet run

sometimes dotnet program won't even run

Thank you so much.

@grindarius
Copy link

grindarius commented Aug 7, 2023

I have the same problem as well. I solved it by changing Date format on windows to Christian era and Regional format to US I hope it will help you. refer https://docs.microsoft.com/en-us/dotnet/core/runtime-config/globalization

Thank you, This helped me too

This happened on my friend's machine where he used to use Thailand as his regional format. The date on his machine used to be written in Thai, Upon changing the regional to English (United States), the problem's solved.

We're on SDK v7

@baronfel
Copy link
Member

baronfel commented Aug 7, 2023

Folks - if you're having this issue can you please comment (or edit your existing comments) with

  • your system's Locale/UI Culture
  • the SDK version you're using?

I think this was fixed in 7.0.200 by #27566, so if you're using 7.0 SDKs make sure you're at least on that version.

@KeNJiKunG
Copy link

Thanks @KalleOlaviNiemitalo, for Windows PowerShell I found the environment variable DOTNET_SYSTEM_GLOBALIZATION_INVARIANT being true solves the issue as current workaround.

> $env:DOTNET_SYSTEM_GLOBALIZATION_INVARIANT='True'
> dotnet run

Thank you so much.

My locale is Thai/Thai. SDK is 7.0.400. I had the issue while try to install Microsoft.dotnet-interactive.

dotnet tool install --global Microsoft.dotnet-interactive --version 1.0.446104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

10 participants