.NET 5 RC1 console app crashes with stackoverflow after calling ToString on a record
See original GitHub issueRelevant 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:
- Create .NET 5 Console Project (I used Visual Studio 2019 Preview on Windows)
- Replace code with Program.cs in RecordDebugStackoverflow.zip
- Start Project
- 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:
- Created 3 years ago
- Comments:10 (7 by maintainers)
Top 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 >
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 Free
Top 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
I can confirm this is fixed in RC2😀
@sparkie108 This package:
https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet-tools&package=Microsoft.Net.Compilers.Toolset&protocolType=NuGet&version=3.9.0-1.20479.3
Should have the fix.