diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 8f905b06c..cb8190bb2 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -526,7 +526,7 @@ namespace ICSharpCode.Decompiler.CSharp if (!processedMethods.Add(part)) continue; try { - ReadCodeMappingInfo(module, declaringType, info, parent, part, connectedMethods, processedNestedTypes); + ReadCodeMappingInfo(module, info, parent, part, connectedMethods, processedNestedTypes); } catch (BadImageFormatException) { // ignore invalid IL } @@ -536,14 +536,16 @@ namespace ICSharpCode.Decompiler.CSharp return info; } - private static void ReadCodeMappingInfo(PEFile module, TypeDefinitionHandle declaringType, CodeMappingInfo info, MethodDefinitionHandle parent, MethodDefinitionHandle part, Queue connectedMethods, HashSet processedNestedTypes) + private static void ReadCodeMappingInfo(PEFile module, CodeMappingInfo info, MethodDefinitionHandle parent, MethodDefinitionHandle part, Queue connectedMethods, HashSet processedNestedTypes) { var md = module.Metadata.GetMethodDefinition(part); if (!md.HasBody()) { info.AddMapping(parent, part); return; - } + } + + var declaringType = md.GetDeclaringType(); var blob = module.Reader.GetMethodBody(md.RelativeVirtualAddress).GetILReader(); while (blob.RemainingBytes > 0) { diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs index 8c8aa382e..2ee23fa63 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs @@ -36,7 +36,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow public static bool IsCompilerGeneratedStateMachine(TypeDefinitionHandle type, MetadataReader metadata) { TypeDefinition td; - if (type.IsNil || !type.IsCompilerGenerated(metadata) || (td = metadata.GetTypeDefinition(type)).GetDeclaringType().IsNil) + if (type.IsNil || (td = metadata.GetTypeDefinition(type)).GetDeclaringType().IsNil) + return false; + if (!(type.IsCompilerGenerated(metadata) || td.GetDeclaringType().IsCompilerGenerated(metadata))) return false; foreach (var i in td.GetInterfaceImplementations()) { var tr = metadata.GetInterfaceImplementation(i).Interface.GetFullTypeName(metadata);