Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`dotnet run` cannot run the project due to `System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex')` exception

See original GitHub issue

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 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:
  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version
F:\Desktop\test>code -v

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

ponlawat-wcommented, Jan 9, 2022

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

> dotnet run
baronfelcommented, 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, so if you’re using 7.0 SDKs make sure you’re at least on that version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

startIndex cannot be larger than length of string - ...
You're trying to take 35 characters after the 26th character (startIndex is zero-based), which is out of range. Second argument for SubString ...
Read more >
startIndex cannot be larger than length of string. Parameter ...
It is the reason to get following error "System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter ...
Read more >
startIndex cannot be larger than length of string
ERROR: System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex') at System.String.
Read more >
Add Scaffolded Item Erorr with startindex cannot be larger ...
There was an error running the selected code generator: 'StartIndex cannot be larger then length of string. (Parameter 'StartIndex')'
Read more >
System.ArgumentOutOfRangeException: startIndex cannot ...
UE5.1 Packaging Error: System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex').
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found