`dotnet run` cannot run the project due to `System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex')` exception
See original GitHub issueDescribe the bug
dotnet run
is unable to run the program due to error but dotnet build
works fine.
To Reproduce
- Use dotnet 6.0
- Create a new dotnet project by do
dotnet new console
- Write some random program (Here’s mine)
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
- 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @KalleOlaviNiemitalo, for Windows PowerShell I found the environment variable
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT
beingtrue
solves the issue as current workaround.Folks - if you’re having this issue can you please comment (or edit your existing comments) with
I think this was fixed in 7.0.200 by https://github.com/dotnet/sdk/pull/27566, so if you’re using 7.0 SDKs make sure you’re at least on that version.