ObjectDumper
ObjectDumper copied to clipboard
[Bug] How to avoid Stack Overflow?
Description
I dump one of my object. I see this message:
Stack overflow.
at System.RuntimeMethodHandle.GetStubIfNeeded(System.RuntimeMethodHandleInternal, System.RuntimeType, System.RuntimeType[])
at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(System.Type[])
at ObjectDumping.Internal.TypeExtensions.GetDefault(System.Type)
at ObjectDumping.Internal.TypeExtensions.TryGetDefault(System.Type)
at ObjectDumping.Internal.PropertyAndValue..ctor(System.Object, System.Reflection.PropertyInfo)
at ObjectDumping.Internal.ObjectDumperConsole+<>c__DisplayClass2_0.<CreateObject>b__3(System.Reflection.PropertyInfo)
at System.Linq.Enumerable+SelectListIterator`2[[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ToList()
at ObjectDumping.Internal.ObjectDumperConsole.CreateObject(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.WriteItems(System.Collections.IEnumerable)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.CreateObject(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.WriteItems(System.Collections.IEnumerable)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.CreateObject(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
...REDACTED... 2000+ lines.
at ObjectDumping.Internal.ObjectDumperConsole.WriteItems(System.Collections.IEnumerable)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.CreateObject(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.WriteItems(System.Collections.IEnumerable)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.CreateObject(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.WriteItems(System.Collections.IEnumerable)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.CreateObject(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.WriteItems(System.Collections.IEnumerable)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.CreateObject(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.WriteItems(System.Collections.IEnumerable)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.Dump(System.Object, DumpOptions)
at ObjectDumper.Dump(System.Object, DumpOptions)
at ObjectDumper.Dump(System.Object)
at ObjectDumperExtensions.Dump(System.Object)
It seems cause by reference loop.
Basic Information
- Version with issue:
4.1.3
- Last known good version: N/A
Screenshots
N/A
Reproduction Link
N/A
That‘s not good. Do you have a sample object which you can share, so I can try to reproduce the problem? Can you check if the same problem also occurs if you use DumpStyle.Csharp?
I tried DumpStyle.Csharp
. The same.
Here is my code snippet. You can run in LINQPad.
http://share.linqpad.net/xt3u9o.linq
Same stuff when I try to dump a Regex.Match GroupCollection.
var match = Regex.Match(logs, RePattern, RegexOptions.IgnoreCase);
Console.WriteLine(match.Groups.Dump());
It might not be the right approach but, as a learner, I was just debugging my code and:
Stack overflow.
at System.RuntimeType.ValidateGenericArguments(System.Reflection.MemberInfo, System.RuntimeType[], System.Exception)
at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(System.Type[])
at ObjectDumping.Internal.TypeExtensions.GetDefault(System.Type)
at ObjectDumping.Internal.TypeExtensions.TryGetDefault(System.Type)
at ObjectDumping.Internal.PropertyAndValue..ctor(System.Object, System.Reflection.PropertyInfo)
at ObjectDumping.Internal.ObjectDumperConsole+<>c__DisplayClass2_0.<CreateObject>b__3(System.Reflection.PropertyInfo)
at System.Linq.Enumerable+SelectListIterator`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Fill(System.ReadOnlySpan`1<System.__Canon>, System.Span`1<System.__Canon>, System.Func`2<System.__Canon,System.__Canon>)
at System.Linq.Enumerable+SelectListIterator`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ToList()
at ObjectDumping.Internal.ObjectDumperConsole.CreateObject(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.WriteItems(System.Collections.IEnumerable)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.CreateObject(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.WriteItems(System.Collections.IEnumerable)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.CreateObject(System.Object, Int32)
...[REDACTED] (tons of lines here)...
at ObjectDumping.Internal.ObjectDumperConsole.WriteItems(System.Collections.IEnumerable)
at ObjectDumping.Internal.ObjectDumperConsole.FormatValue(System.Object, Int32)
at ObjectDumping.Internal.ObjectDumperConsole.Dump(System.Object, DumpOptions)
at ObjectDumper.Dump(System.Object, DumpOptions)
at ObjectDumper.Dump(System.Object)
at ObjectDumperExtensions.Dump(System.Object)
The reason is that ObjectDumper.NET doesn't handle the self-containing collections. See closed PR!100
@ycherkes Why the PR been closed?
@doggy8088 this question is for @thomasgalliker. I can just say that it is one of couple reasons why I developed my own library with no such issues.
I have no idea why I closed the PR @ycherkes Don‘t take it personally. As soon as I have sone time I gonna look into it.
Thanks for reporting this @doggy8088
This was a tough one. There was some refactoring needed to make the circular reference comments look nicely.
@doggy8088 you‘ll find a pre-release 4.2.x on nuget.org. Thanks to @ycherkes for raising this issue too. I‘m, again, sorry to have ignored your PR. No hurt feelings please 🌻👍🏻
Can you please let me know if this solves your problem?
I created a unit test for the Regex-Match case, and it dumps some properties.. I have no idea if this is what you expect @doggy8088. At least it doesn‘t end in a dead loop anymore.
@doggy8088 and @BranchScope can you verify if the latest pre-release solves the problem? I‘ll merge this change if someone could check.
@thomasgalliker It works perfectly. Thank you!
In my sample code, the result is:
{LiteralInline}
IsFirstCharacterEscaped: false
Parent: null --> Circular reference detected
PreviousSibling: null
NextSibling: null
IsClosed: false
Column: 2
Line: 1