diff --git a/Directory.Build.props b/Directory.Build.props
index 6c371ea..9a043fe 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -3,9 +3,6 @@
latest
true
-
- $(DefineConstants);HAS_ASYNC_ENUMERATOR
-
diff --git a/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs b/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs
index 705233c..95c8321 100644
--- a/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs
+++ b/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs
@@ -20,6 +20,24 @@ namespace System.Diagnostics
public partial class EnhancedStackTrace
{
private static readonly Type? StackTraceHiddenAttributeType = Type.GetType("System.Diagnostics.StackTraceHiddenAttribute", false);
+ private static readonly Type? AsyncIteratorStateMachineAttributeType = Type.GetType("System.Runtime.CompilerServices.AsyncIteratorStateMachineAttribute", false);
+
+ static EnhancedStackTrace()
+ {
+ if (AsyncIteratorStateMachineAttributeType != null) return;
+
+ Assembly mba;
+ try
+ {
+ mba = Assembly.Load("Microsoft.Bcl.AsyncInterfaces");
+ }
+ catch
+ {
+ return;
+ }
+
+ AsyncIteratorStateMachineAttributeType = mba.GetType("System.Runtime.CompilerServices.AsyncIteratorStateMachineAttribute", false);
+ }
private static List GetFrames(Exception exception)
{
@@ -706,6 +724,10 @@ namespace System.Diagnostics
{
return false;
}
+ if (method.Name == "GetResult" && method.DeclaringType?.FullName == "System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1")
+ {
+ return false;
+ }
if (type == typeof(Task) || type.DeclaringType == typeof(Task))
{
if (method.Name.Contains(".cctor"))
@@ -755,7 +777,7 @@ namespace System.Diagnostics
}
}
}
-
+
if (type.Namespace == "Ply")
{
if (type.DeclaringType?.Name == "TplPrimitives")
@@ -866,10 +888,8 @@ namespace System.Diagnostics
{
foundAttribute = true;
foundIteratorAttribute |= asma is IteratorStateMachineAttribute
-#if HAS_ASYNC_ENUMERATOR
- || asma is AsyncIteratorStateMachineAttribute
-#endif
- ;
+ || AsyncIteratorStateMachineAttributeType != null
+ && AsyncIteratorStateMachineAttributeType.IsInstanceOfType(asma);
}
}
diff --git a/test/Ben.Demystifier.Test/AsyncEnumerableTests.cs b/test/Ben.Demystifier.Test/AsyncEnumerableTests.cs
index 487ba27..26df76d 100644
--- a/test/Ben.Demystifier.Test/AsyncEnumerableTests.cs
+++ b/test/Ben.Demystifier.Test/AsyncEnumerableTests.cs
@@ -1,4 +1,3 @@
-#if HAS_ASYNC_ENUMERATOR
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -63,4 +62,3 @@ namespace Ben.Demystifier.Test
}
}
}
-#endif
diff --git a/test/Ben.Demystifier.Test/Ben.Demystifier.Test.csproj b/test/Ben.Demystifier.Test/Ben.Demystifier.Test.csproj
index fc3126a..04286eb 100644
--- a/test/Ben.Demystifier.Test/Ben.Demystifier.Test.csproj
+++ b/test/Ben.Demystifier.Test/Ben.Demystifier.Test.csproj
@@ -2,13 +2,14 @@
netcoreapp2.1;netcoreapp3.1;net5.0;net6.0
- $(TargetFrameworks);net46
+ $(TargetFrameworks);net461
true
..\..\src\Ben.Demystifier\key.snk
false
+