question-mark
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.

.NET 5 RC1 console app crashes with stackoverflow after calling ToString on a record

See original GitHub issue

Relevant code:

	public record ModuleManifest(string Name, Version Version);
	public record ModuleSet(ImmutableArray<ModuleManifest> Manifests) {
		public static ModuleSet Empty { get; } = new ModuleSet(ImmutableArray<ModuleManifest>.Empty);
	}

	public static ModuleSet ActiveModuleSet { get; private set; } = ModuleSet.Empty;

ActiveModuleSet.ToString(); //Crash

Exception callstack (console output):

Stack overflow.
   at System.Text.StringBuilder.ThreadSafeCopy(Char*, Char[], Int32, Int32)
   at System.Text.StringBuilder.Append(Char*, Int32)
   at System.Text.StringBuilder.AppendHelper(System.String)
   at System.Text.StringBuilder.Append(System.String)
   at RecordDebugStackoverflow.Program+ModuleSet.PrintMembers(System.Text.StringBuilder)
   at RecordDebugStackoverflow.Program+ModuleSet.ToString()
   at System.Text.StringBuilder.Append(System.Object)
   at RecordDebugStackoverflow.Program+ModuleSet.PrintMembers(System.Text.StringBuilder)
   at RecordDebugStackoverflow.Program+ModuleSet.ToString()
   at System.Text.StringBuilder.Append(System.Object)
   ...

To reproduce:

  1. Create .NET 5 Console Project (I used Visual Studio 2019 Preview on Windows)
  2. Replace code with Program.cs in RecordDebugStackoverflow.zip
  3. Start Project
  4. Program crash

I previously reported it at https://developercommunity.visualstudio.com/content/problem/1201798/debug-session-crashes-after-hovering-a-field-with.html but then noticed that this wasn’t a debugging issue within Visual Studio.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

C# record ToString() causes stack overflow and stops ...
1 Answer 1 ... The problem is that ToString(), which gets automatically written by the compiler, calls .ToString() again on every property. If...
Read more >
Performance Improvements in .NET 7
NET 7 is fast. Really fast. This post deep-dives into hundreds of performance improvements that contributed to that reality.
Read more >
Fix list for IBM WebSphere Application Server V8.5
IBM WebSphere Application Server provides periodic fixes for the base and Network Deployment editions of release V8.5. The following is a complete listing ......
Read more >
Visual Studio 2022 version 17.0 Release Notes
NET 6.0 where a malicious client could cause a stack overflow which may result in a denial of service attack when an attacker...
Read more >
C# 9 Record: Compiler Created ToString() Code can Lead ...
If a record declaration creates a cyclical reference, the compiler generated ToString() causes a stack overflow.
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found