Compiler generated incorrect code for anonymous methods [MS BUG FIXED]

别来无恙 提交于 2019-11-30 04:22:05
Cheng Chen

It is confirmed as a bug and now fixed

Update: the Connect article no longer exists. The bug is fixed.

Ondra

At first - This is a possible way how to fix this, but probably not an answer to your question. (But comments don´t have code formating)

I believe this is similar to this: Outer Variable Trap, because you are using Foo() method as a variable and there is a bug (or maybe a feature) in .NET

I have tried to change Bang() method to this

public void Bang()
{
    Action baseMethod = base.Foo<string>;
    Action bang = new Action(delegate { baseMethod(); });
    bang();    //VerificationException is thrown
}

And it works and the result is "base"

I hope it helps a little bit.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!