TypeLoad Exception

  • Thread starter Thread starter Tunga Torgal
  • Start date Start date
T

Tunga Torgal

Hi,

I'm getting an System.TypeLoadException with this type def:

[StructLayout(LayoutKind.Explicit, CharSet=CharSet.Ansi)]
public struct SCFEDBTxnItem
{
[FieldOffset(0)] public SCFEDBTxnItemHeader sHeader;
[FieldOffset(0)] public SCFEDBTxnOrderItem sOrder;
[FieldOffset(0)] public SCFEDBTxnTradeItem sTrade;
[FieldOffset(0)] public SCFEDBTxnErrorItem sError;
[FieldOffset(0)] public SCFEDBTxnRequestItem sRequest;
}



So, what is the problem?
 
Tunga,

What is the exception you are getting? It is most likely that the type
load exception is not coming from the code, but some other factor. Can you
give the full details of the exception?
 
Tunga,
From what I see its not byte aligned. Every feild seems to be at
offset 0. If for example sHeader is 4 bytes long then FieldOffset for
the sOrder field should be FieldOffset(4)
Hope that helps

Tunga said:
Hi,

I'm getting an System.TypeLoadException with this type def:

[StructLayout(LayoutKind.Explicit, CharSet=CharSet.Ansi)]
public struct SCFEDBTxnItem
{
[FieldOffset(0)] public SCFEDBTxnItemHeader sHeader;
[FieldOffset(0)] public SCFEDBTxnOrderItem sOrder;
[FieldOffset(0)] public SCFEDBTxnTradeItem sTrade;
[FieldOffset(0)] public SCFEDBTxnErrorItem sError;
[FieldOffset(0)] public SCFEDBTxnRequestItem sRequest;
}



So, what is the problem?
 
First, this is union...
So, everyfield must start at the same offset...

Am I wrong? Maybe, I did not understand the concept of fieldoffsets and
layoutkind.explicit...

Dilip Krishnan said:
Tunga,
From what I see its not byte aligned. Every feild seems to be at
offset 0. If for example sHeader is 4 bytes long then FieldOffset for
the sOrder field should be FieldOffset(4)
Hope that helps

Tunga said:
Hi,

I'm getting an System.TypeLoadException with this type def:

[StructLayout(LayoutKind.Explicit, CharSet=CharSet.Ansi)]
public struct SCFEDBTxnItem
{
[FieldOffset(0)] public SCFEDBTxnItemHeader sHeader;
[FieldOffset(0)] public SCFEDBTxnOrderItem sOrder;
[FieldOffset(0)] public SCFEDBTxnTradeItem sTrade;
[FieldOffset(0)] public SCFEDBTxnErrorItem sError;
[FieldOffset(0)] public SCFEDBTxnRequestItem sRequest;
}



So, what is the problem?

--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
 
Aah unions! I'm guessing, but I think its possibly because they field
offsets dont work for reference types? Basically it cant compute the
union type because it cant compute the sizes at design time?

Tunga said:
First, this is union...
So, everyfield must start at the same offset...

Am I wrong? Maybe, I did not understand the concept of fieldoffsets and
layoutkind.explicit...

Tunga,
From what I see its not byte aligned. Every feild seems to be at
offset 0. If for example sHeader is 4 bytes long then FieldOffset for
the sOrder field should be FieldOffset(4)
Hope that helps

Tunga Torgal wrote:

Hi,

I'm getting an System.TypeLoadException with this type def:

[StructLayout(LayoutKind.Explicit, CharSet=CharSet.Ansi)]
public struct SCFEDBTxnItem
{
[FieldOffset(0)] public SCFEDBTxnItemHeader sHeader;
[FieldOffset(0)] public SCFEDBTxnOrderItem sOrder;
[FieldOffset(0)] public SCFEDBTxnTradeItem sTrade;
[FieldOffset(0)] public SCFEDBTxnErrorItem sError;
[FieldOffset(0)] public SCFEDBTxnRequestItem sRequest;
}



So, what is the problem?

--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
 
Back
Top