2

可能重复:
编译器为匿名方法生成了不正确的代码

为什么下面的代码原因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 的回复。票#768801

4

0 回答 0