Reputation: 398
class Program
{
static void Main(string[] args)
{
var t = new TestImpl();
Console.WriteLine(t.Test(TestEnum.Value));
}
}
public class AbstractTest<T> where T:new()
{
public virtual T TestBase(TestEnum v)
{
return new T();
}
}
public class Product
{
public int Id { get; set; }
}
public enum TestEnum
{
Value
}
public class TestImpl : AbstractTest<Product>
{
public int Test(TestEnum ev)
{
Func<int> f = () =>
{
var result = base.TestBase(ev);
return result.Id;
};
return f();
}
}
Hi All:
I have a issue like the code (run on the .net4.0).
it will throw exception:An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
if make " var result = base.TestBase(ev);" chanage to " var result = this.TestBase(ev);" this will normal. if not use lambda func ,use common func like this:
public class TestImpl : AbstractTest<Product>
{
public int Test(TestEnum ev)
{
Func<int> f = () =>
{
//var result = base.TestBase(ev);
// return result.Id;
return TestResult(ev);
};
return f();
}
private int TestResult(TestEnum ev)
{
var result = base.TestBase(ev);
return result.Id;
}
}
that is ok. i think is "base" or "this" point to different case or other .
Who can tell me why and what's happened? what's the theory? thanks.
Upvotes: 2
Views: 183
Reputation: 174309
The error you get normally is a result of a 64 bit application trying to load a 32 bit assembly or vice versa.
However, I could actually reproduce the problem on a machine without .NET 4.5 installed.
The generated IL of the anonymous class seems to be really invalid, because ILSpy even fails to decompile it.
Upvotes: 1