R
Robert Bouillon
I'm creating a managed wrapper for printing, and I defined a struct to
marshal some data. Because of .NET interop limitations on .NET CF, I
defined the struct as LayoutKind.Explicit. The CLR threw a "Could not
load type" on the implementing class when I declared the a variable for
the struct. Changing the StructLayout to LayoutKind.Sequential fixed
the problem, but I may not always be able to fix the problem that way.
What was I doing wrong? Is this a CLR bug? ILDASM showed the DLL did
indeed have the class, so it's not a compiler issue....
public class MyClass
{
//Commenting out this line stops the error...
private DocumentInformation _info;
{...}
//Changind this to LayoutKind.Sequential also stops the error...
[StructLayout(LayoutKind.Explicit)]
private struct DocumentInformation {
[FieldOffset(0)]
public short cbSize;
[FieldOffset(2)]
public IntPtr lpszDocName;
[FieldOffset(6)]
public IntPtr lpszOutput;
[FieldOffset(10)]
public IntPtr lpszDatatype;
[FieldOffset(14)]
public uint fwType;
}
marshal some data. Because of .NET interop limitations on .NET CF, I
defined the struct as LayoutKind.Explicit. The CLR threw a "Could not
load type" on the implementing class when I declared the a variable for
the struct. Changing the StructLayout to LayoutKind.Sequential fixed
the problem, but I may not always be able to fix the problem that way.
What was I doing wrong? Is this a CLR bug? ILDASM showed the DLL did
indeed have the class, so it's not a compiler issue....
public class MyClass
{
//Commenting out this line stops the error...
private DocumentInformation _info;
{...}
//Changind this to LayoutKind.Sequential also stops the error...
[StructLayout(LayoutKind.Explicit)]
private struct DocumentInformation {
[FieldOffset(0)]
public short cbSize;
[FieldOffset(2)]
public IntPtr lpszDocName;
[FieldOffset(6)]
public IntPtr lpszOutput;
[FieldOffset(10)]
public IntPtr lpszDatatype;
[FieldOffset(14)]
public uint fwType;
}