diff --git a/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs b/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs index f0994f8..bee86ba 100644 --- a/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs +++ b/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs @@ -663,8 +663,13 @@ namespace System.Diagnostics { return false; } - if (type == typeof(Task)) + if (type == typeof(Task) || type.DeclaringType == typeof(Task)) { + if (method.Name.Contains(".cctor")) + { + return false; + } + switch (method.Name) { case "ExecuteWithThreadLocal": @@ -672,15 +677,24 @@ namespace System.Diagnostics case "ExecutionContextCallback": case "ExecuteEntry": case "InnerInvoke": + case "ExecuteEntryUnsafe": + case "ExecuteFromThreadPool": + case "s_ecCallback": return false; } } if (type == typeof(ExecutionContext)) { + if (method.Name.Contains(".cctor")) + { + return false; + } + switch (method.Name) { case "RunInternal": case "Run": + case "RunFromThreadPoolDispatchLoop": return false; } } diff --git a/src/Ben.Demystifier/TypeNameHelper.cs b/src/Ben.Demystifier/TypeNameHelper.cs index bfa1559..070276f 100644 --- a/src/Ben.Demystifier/TypeNameHelper.cs +++ b/src/Ben.Demystifier/TypeNameHelper.cs @@ -60,9 +60,8 @@ namespace System.Diagnostics } var genericPartIndex = type.Name.IndexOf('`'); - Debug.Assert(genericPartIndex >= 0); - return type.Name.Substring(0, genericPartIndex); + return (genericPartIndex >= 0) ? type.Name.Substring(0, genericPartIndex) : type.Name; } private static void ProcessType(StringBuilder builder, Type type, DisplayNameOptions options) diff --git a/test/Ben.Demystifier.Test/AggregateException.cs b/test/Ben.Demystifier.Test/AggregateException.cs index 3c0034a..59fe292 100644 --- a/test/Ben.Demystifier.Test/AggregateException.cs +++ b/test/Ben.Demystifier.Test/AggregateException.cs @@ -37,14 +37,28 @@ namespace Ben.Demystifier.Test var trace = string.Join("", stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) // Remove items that vary between test runners .Where(s => - s != " at Task Ben.Demystifier.Test.DynamicCompilation.DoesNotPreventStackTrace()+() => { }" && - !s.Contains("System.Threading.Tasks.Task.WaitAll") + (s != " at Task Ben.Demystifier.Test.DynamicCompilation.DoesNotPreventStackTrace()+() => { }" && + !s.Contains("System.Threading.Tasks.Task.WaitAll")) ) .Skip(1) .ToArray()) // Remove Full framework back arrow .Replace("<---", ""); - +#if NET5_0 || NETCOREAPP3_1 + var expected = string.Join("", new[] { + " ---> System.ArgumentException: Value does not fall within the expected range.", + " at async Task Ben.Demystifier.Test.AggregateException.Throw1()", + " at async void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()+(?) => { }", + " --- End of inner exception stack trace ---", + " at void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()", + " ---> (Inner Exception #1) System.NullReferenceException: Object reference not set to an instance of an object.", + " at async Task Ben.Demystifier.Test.AggregateException.Throw2()", + " at async void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()+(?) => { }", + " ---> (Inner Exception #2) System.InvalidOperationException: Operation is not valid due to the current state of the object.", + " at async Task Ben.Demystifier.Test.AggregateException.Throw3()", + " at async void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()+(?) => { }" + }); +#else var expected = string.Join("", new[] { " at async Task Ben.Demystifier.Test.AggregateException.Throw1()", " at async void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()+(?) => { }", @@ -59,7 +73,7 @@ namespace Ben.Demystifier.Test "---> (Inner Exception #2) System.InvalidOperationException: Operation is not valid due to the current state of the object.", " at async Task Ben.Demystifier.Test.AggregateException.Throw3()", " at async void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()+(?) => { }"}); - +#endif Assert.Equal(expected, trace); } diff --git a/test/Ben.Demystifier.Test/DynamicCompilation.cs b/test/Ben.Demystifier.Test/DynamicCompilation.cs index 3731011..e9a7364 100644 --- a/test/Ben.Demystifier.Test/DynamicCompilation.cs +++ b/test/Ben.Demystifier.Test/DynamicCompilation.cs @@ -44,6 +44,7 @@ namespace Ben.Demystifier.Test s != " at void System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, object state)" && s != " at Task Ben.Demystifier.Test.DynamicCompilation.DoesNotPreventStackTrace()+() => { }" ) + .Select(s => Regex.Replace(s, "lambda_method[0-9]+\\(", "lambda_method(")) .ToArray(); Assert.Equal( diff --git a/test/Ben.Demystifier.Test/NonThrownException.cs b/test/Ben.Demystifier.Test/NonThrownException.cs index ef5abf2..ef99cf2 100644 --- a/test/Ben.Demystifier.Test/NonThrownException.cs +++ b/test/Ben.Demystifier.Test/NonThrownException.cs @@ -31,13 +31,24 @@ namespace Ben.Demystifier.Test stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace); var trace = stackTrace.Split(new[]{Environment.NewLine}, StringSplitOptions.None); +#if NETCOREAPP3_1 || NET5_0 Assert.Equal( new[] { - "System.Exception: Exception of type 'System.Exception' was thrown. ---> System.Exception: Exception of type 'System.Exception' was thrown.", + "System.Exception: Exception of type 'System.Exception' was thrown.", + " ---> System.Exception: Exception of type 'System.Exception' was thrown.", " at Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()+() => { }", " at async Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()", " --- End of inner exception stack trace ---"}, trace); +#else + Assert.Equal( + new[] { + "System.Exception: Exception of type 'System.Exception' was thrown. ---> System.Exception: Exception of type 'System.Exception' was thrown.", + " at Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()+() => { }", + " at async Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()", + " --- End of inner exception stack trace ---"}, + trace); +#endif // Act try @@ -54,6 +65,18 @@ namespace Ben.Demystifier.Test stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace); trace = stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.None); +#if NETCOREAPP3_1 || NET5_0 + Assert.Equal( + new[] { + "System.Exception: Exception of type 'System.Exception' was thrown.", + " ---> System.Exception: Exception of type 'System.Exception' was thrown.", + " at Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()+() => { }", + " at async Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()", + " --- End of inner exception stack trace ---", + " at async Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()" + }, + trace); +#else Assert.Equal( new[] { "System.Exception: Exception of type 'System.Exception' was thrown. ---> System.Exception: Exception of type 'System.Exception' was thrown.", @@ -63,6 +86,7 @@ namespace Ben.Demystifier.Test " at async Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()" }, trace); +#endif } [Fact]