2

Possible Duplicate:
Compiler generated incorrect code for anonymous methods

Why following code cause 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. Both x64 and x86 machines.

UPD. Waiting for response from MS. Ticket #768801

Community
  • 1
  • 1
lorond
  • 3,856
  • 2
  • 37
  • 52

0 Answers0