runtime: ExcecutionEngineException when using StringBuilder on long strings

Description

This issue was originally reported to Visual Studio (https://developercommunity.visualstudio.com/t/Prevent-using-precompiled-images-in-de/10363031) because it seems to only reproduce when turning off precompiled images under the debugger.

Reproduction Steps

  1. Create a simple dotnet 7 console application with the following code:
var count = 100000;
_ = string.Join(" ", Enumerable.Range(0, count).Select(_ => "Hello world!"));
  1. In Visual Studio, turn on the option in Tools > Options > Debugging > General > “Prevent using precompiled images…”

  2. Start debugging.

Expected behavior

The application runs to completion.

Actual behavior

Either an ArgumentOutOfRangeException or an ExecutionEngineException is thrown.

Regression?

No response

Known Workarounds

No response

Configuration

Using dotnet 7.0.5, and the latest dotnet 8 preview. Windows 11 x64

Other information

I think that it might be due to an overflow error while computing the length of the underlying span that is being used by the StringBuilder.

This repros in both dotnet 7, and dotnet 8 preview, though the location that the error is thrown from in dotnet 8 is different. I have heap dumps of the crashing processes in dotnet 7. I can make some for dotnet 8 if necessary as well.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Right, there’s currently no way to test this config outside of debugging.

As I suspected

this->opts.jitFlags->m_jitFlags,x
0x0000000004080214

DEBUG_CODE
DEBUG_INFO
FROZEN_ALLOC_ALLOWED
BBINSTR_IF_LOOPS
TIER0

Either the jit interface should remove TIER0 or the jit should ignore it if DEBUG_CODE is present.