diff --git a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs index 3d49bf927..10e482e7c 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs @@ -162,6 +162,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// /// Replaces loads of 'this' with the target expression. + /// Async delegates use: ldobj(ldloca this). /// class ReplaceDelegateTargetVisitor : ILVisitor { @@ -183,12 +184,21 @@ namespace ICSharpCode.Decompiler.IL.Transforms protected internal override void VisitLdLoc(LdLoc inst) { - if (inst.MatchLdLoc(thisVariable)) { + if (inst.Variable == thisVariable) { inst.ReplaceWith(target.Clone()); return; } base.VisitLdLoc(inst); } + + protected internal override void VisitLdObj(LdObj inst) + { + if (inst.Target.MatchLdLoca(thisVariable)) { + inst.ReplaceWith(target.Clone()); + return; + } + base.VisitLdObj(inst); + } } ///