Lambda中的BadImageFormatException与基本调用

时间:2012-10-25 15:23:46

标签: c# .net

  

可能重复:
  Compiler generated incorrect code for anonymous methods

为什么以下代码导致BadImageFormatException

public static void Main()
{
    var c = new Child();
    Console.WriteLine(c.Something());
}

public class Base<T>
{
    public virtual T Something()
    {
        return default(T);
    }
}

public class Child : Base<int>
{
    public override int Something()
    {
        //return base.Something(); //This one works well

        //Func<int> func = base.Something;
        //func(); //Works well too

        Func<int> func = () => base.Something();
        return func(); //BadImageFormatException
    }
}

BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

.NET 4.0。 x64和x86机器。

UPD。等待MS的回复。 Ticket #768801

0 个答案:

没有答案