diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 1ad2fe90c..a7f347d2c 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -525,9 +525,13 @@ namespace ICSharpCode.Decompiler.CSharp foreach (var ca in provider.CustomAttributes) { CollectNamespacesForDecompilation(ca.AttributeType, namespaces, visited); CollectNamespacesForDecompilation(ca.Constructor, namespaces, visited); + bool isAsyncStateMachine = ca.AttributeType.FullName == "System.Runtime.CompilerServices.AsyncStateMachineAttribute"; foreach (var val in ca.ConstructorArguments) { - if (val.Value is TypeReference tr) + if (val.Value is TypeReference tr) { namespaces.Add(tr.Namespace); + if (isAsyncStateMachine) + CollectNamespacesForDecompilation(new[] { tr.ResolveWithinSameModule() }, namespaces, visited); + } } } } @@ -664,6 +668,17 @@ namespace ICSharpCode.Decompiler.CSharp CollectNamespacesForDecompilation(p.ParameterType, namespaces, visited); } } + if (methodDef.HasGenericParameters) { + foreach (var gp in methodDef.GenericParameters) { + if (gp.HasConstraints) { + foreach (var constraint in gp.Constraints) { + // Avoid infinite recursion + if (!(constraint is GenericInstanceType git && git.ElementType == gp.Owner)) + CollectNamespacesForDecompilation(constraint, namespaces, visited); + } + } + } + } if (methodDef.HasBody) { CollectNamespacesForDecompilation(methodDef.Body, namespaces, visited); }