A
Andrew
Hi. I'm fairly new to Compact Framework and have run into a problem that
has me scratching my head. Hopefully it's just ignorance on my part, but
I'd appreciate any help.
My problem has to do with inheritance. I have a base class (MyBase) with >
128 bytes of value types (doubles, longs, structs, etc). I can instantiate
an object of this type without any problems.
I also have a derived class (MyDerived) that derives from it. When I
instantiate an object of this type I get a System.TypeLoad.Exception. What
puzzles me is that when I modify the base class to declare <= 128 bytes of
value types, the exception goes away. To make things more interesting, if I
instantiate an object of the derived type and assign it to a base class
object (see below), I get a different exception
(System.MissingMethod.Exception).
Is there a limitation in .NET CF that I am not aware of?
I've tried this code on a regular .NET Framework app and it works fine.
I've boiled everything down to a simple test case below.
public Form1()
{
InitializeComponent();
//MyBase x = new MyBase(); // ok
//MyBase y = new MyDerived(); // System.MissingMethodException
MyDerived z = new MyDerived(); // System.TypeLoadException
}
public class MyBase
{
// Declaring more than 128 bytes here causes an exception when a
// derived class is instantiated.
// Not a problem if you dynamically allocate (array) though.
public long dummy1;
public long dummy2;
public long dummy3;
public long dummy4;
public long dummy5;
public long dummy6;
public long dummy7;
public long dummy8;
public long dummy9;
public long dummy10;
public long dummy11;
public long dummy12;
public long dummy13;
public long dummy14;
public long dummy15;
public long dummy16;
public byte oneByte; // Comment this line out and everything
works fine.
public MyBase()
{
}
}
public class MyDerived: MyBase
{
public MyDerived(): base()
{
}
}
has me scratching my head. Hopefully it's just ignorance on my part, but
I'd appreciate any help.
My problem has to do with inheritance. I have a base class (MyBase) with >
128 bytes of value types (doubles, longs, structs, etc). I can instantiate
an object of this type without any problems.
I also have a derived class (MyDerived) that derives from it. When I
instantiate an object of this type I get a System.TypeLoad.Exception. What
puzzles me is that when I modify the base class to declare <= 128 bytes of
value types, the exception goes away. To make things more interesting, if I
instantiate an object of the derived type and assign it to a base class
object (see below), I get a different exception
(System.MissingMethod.Exception).
Is there a limitation in .NET CF that I am not aware of?
I've tried this code on a regular .NET Framework app and it works fine.
I've boiled everything down to a simple test case below.
public Form1()
{
InitializeComponent();
//MyBase x = new MyBase(); // ok
//MyBase y = new MyDerived(); // System.MissingMethodException
MyDerived z = new MyDerived(); // System.TypeLoadException
}
public class MyBase
{
// Declaring more than 128 bytes here causes an exception when a
// derived class is instantiated.
// Not a problem if you dynamically allocate (array) though.
public long dummy1;
public long dummy2;
public long dummy3;
public long dummy4;
public long dummy5;
public long dummy6;
public long dummy7;
public long dummy8;
public long dummy9;
public long dummy10;
public long dummy11;
public long dummy12;
public long dummy13;
public long dummy14;
public long dummy15;
public long dummy16;
public byte oneByte; // Comment this line out and everything
works fine.
public MyBase()
{
}
}
public class MyDerived: MyBase
{
public MyDerived(): base()
{
}
}