|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem with Structures using FieldOffset -- BUG?into a problem. When I try to setup a union of data array or message type, I get the following error: System.TypeLoadException: Could not load type 'Test.Message' from assembly 'Test, Version=1.0.2228.19435, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 1 that is incorrectly aligned or overlapped by a non-object field. WHY? <StructLayout(LayoutKind.Explicit)> _ Public Structure R_OMNI_LINK_MESSAGE <FieldOffset(0)> Public MessageLength As Byte ' ....... THIS ONE DOESN'T WORK!!.... Throws Error <FieldOffset(1), MarshalAs(UnmanagedType.ByValArray, SizeConst:=255)> Public Data() As Byte '............................................................................... <FieldOffset(1)> Public MessageType As Byte <FieldOffset(2)> Public NAME_DATA As olmNAME_DATA ' 8bit / 16bit <FieldOffset(2)> Public EVENT_LOG_DATA As olmEVENT_LOG_DATA <FieldOffset(2)> Public COMMAND_MESSAGE As olmCOMMAND_MESSAGE <FieldOffset(2)> Public SET_TIME As olmSET_TIME <FieldOffset(2)> Public SYSTEM_STATUS As olmSYSTEM_STATUS <FieldOffset(2)> Public REQUEST_ZONE_STATUS As olmREQUEST_ZONE_STATUS <FieldOffset(2)> Public REQUEST_UNIT_STATUS As olmREQUEST_UNIT_STATUS '8bit / 16bit <FieldOffset(2)> Public REQUEST_AUXILIARY_STATUS As olmREQUEST_AUXILIARY_STATUS <FieldOffset(2)> Public REQUEST_THERMOSTAT_STATUS As olmREQUEST_THERMOSTAT_STATUS <FieldOffset(2)> Public LOGIN As olmLOGIN <FieldOffset(2)> Public REQUEST_SECURITY_CODE_VALIDATION As olmREQUEST_SECURITY_CODE_VALIDATION <FieldOffset(2)> Public SECURITY_CODE_VALIDATION As olmSECURITY_CODE_VALIDATION End Structure Quick update... If I change the StructLayout to
<StructLayout(LayoutKind.Auto)>, the code compiles without errors... haven't check to see if it works as intended... anyone see any problems with using Auto? Thanks, Danny Show quoteHide quote "Danny Mavromatis" <n***@mavromatis.com> wrote in message news:11un3j0k2904efc@corp.supernews.com... > I'm trying to set up a structure using unions (fieldoffset) and I'm > running > into a problem. When I try to setup a union of data array or > message type, I get the following error: > > System.TypeLoadException: Could not load type 'Test.Message' from assembly > 'Test, Version=1.0.2228.19435, Culture=neutral, PublicKeyToken=null' > because > it contains an object field at offset 1 that is incorrectly aligned or > overlapped by a non-object field. > > WHY? > > <StructLayout(LayoutKind.Explicit)> _ > Public Structure R_OMNI_LINK_MESSAGE > <FieldOffset(0)> Public MessageLength As Byte > ' ....... THIS ONE DOESN'T WORK!!.... Throws Error > <FieldOffset(1), MarshalAs(UnmanagedType.ByValArray, SizeConst:=255)> > Public > Data() As Byte > '............................................................................... > <FieldOffset(1)> Public MessageType As Byte > <FieldOffset(2)> Public NAME_DATA As olmNAME_DATA ' 8bit / 16bit > <FieldOffset(2)> Public EVENT_LOG_DATA As olmEVENT_LOG_DATA > <FieldOffset(2)> Public COMMAND_MESSAGE As olmCOMMAND_MESSAGE > <FieldOffset(2)> Public SET_TIME As olmSET_TIME > <FieldOffset(2)> Public SYSTEM_STATUS As olmSYSTEM_STATUS > <FieldOffset(2)> Public REQUEST_ZONE_STATUS As olmREQUEST_ZONE_STATUS > <FieldOffset(2)> Public REQUEST_UNIT_STATUS As olmREQUEST_UNIT_STATUS > '8bit > / 16bit > <FieldOffset(2)> Public REQUEST_AUXILIARY_STATUS As > olmREQUEST_AUXILIARY_STATUS > <FieldOffset(2)> Public REQUEST_THERMOSTAT_STATUS As > olmREQUEST_THERMOSTAT_STATUS > <FieldOffset(2)> Public LOGIN As olmLOGIN > <FieldOffset(2)> Public REQUEST_SECURITY_CODE_VALIDATION As > olmREQUEST_SECURITY_CODE_VALIDATION > <FieldOffset(2)> Public SECURITY_CODE_VALIDATION As > olmSECURITY_CODE_VALIDATION > End Structure > > > > More updates: Changing it to Auto isn't what I need since the fieldoffsets,
don't seem to be doing anything with Auto. Show quoteHide quote "Danny Mavromatis" <n***@mavromatis.com> wrote in message news:11un3vtn79j4s9b@corp.supernews.com... > Quick update... If I change the StructLayout to > <StructLayout(LayoutKind.Auto)>, the code compiles without errors... > haven't check to see if it works as intended... anyone see any problems > with using Auto? > > Thanks, > Danny > > "Danny Mavromatis" <n***@mavromatis.com> wrote in message > news:11un3j0k2904efc@corp.supernews.com... >> I'm trying to set up a structure using unions (fieldoffset) and I'm >> running >> into a problem. When I try to setup a union of data array or >> message type, I get the following error: >> >> System.TypeLoadException: Could not load type 'Test.Message' from >> assembly >> 'Test, Version=1.0.2228.19435, Culture=neutral, PublicKeyToken=null' >> because >> it contains an object field at offset 1 that is incorrectly aligned or >> overlapped by a non-object field. >> >> WHY? >> >> <StructLayout(LayoutKind.Explicit)> _ >> Public Structure R_OMNI_LINK_MESSAGE >> <FieldOffset(0)> Public MessageLength As Byte >> ' ....... THIS ONE DOESN'T WORK!!.... Throws Error >> <FieldOffset(1), MarshalAs(UnmanagedType.ByValArray, SizeConst:=255)> >> Public >> Data() As Byte >> '............................................................................... >> <FieldOffset(1)> Public MessageType As Byte >> <FieldOffset(2)> Public NAME_DATA As olmNAME_DATA ' 8bit / 16bit >> <FieldOffset(2)> Public EVENT_LOG_DATA As olmEVENT_LOG_DATA >> <FieldOffset(2)> Public COMMAND_MESSAGE As olmCOMMAND_MESSAGE >> <FieldOffset(2)> Public SET_TIME As olmSET_TIME >> <FieldOffset(2)> Public SYSTEM_STATUS As olmSYSTEM_STATUS >> <FieldOffset(2)> Public REQUEST_ZONE_STATUS As olmREQUEST_ZONE_STATUS >> <FieldOffset(2)> Public REQUEST_UNIT_STATUS As olmREQUEST_UNIT_STATUS >> '8bit >> / 16bit >> <FieldOffset(2)> Public REQUEST_AUXILIARY_STATUS As >> olmREQUEST_AUXILIARY_STATUS >> <FieldOffset(2)> Public REQUEST_THERMOSTAT_STATUS As >> olmREQUEST_THERMOSTAT_STATUS >> <FieldOffset(2)> Public LOGIN As olmLOGIN >> <FieldOffset(2)> Public REQUEST_SECURITY_CODE_VALIDATION As >> olmREQUEST_SECURITY_CODE_VALIDATION >> <FieldOffset(2)> Public SECURITY_CODE_VALIDATION As >> olmSECURITY_CODE_VALIDATION >> End Structure >> >> >> >> > > >System.TypeLoadException: Could not load type 'Test.Message' from assembly The error message pretty much tells you why. You can't have a>'Test, Version=1.0.2228.19435, Culture=neutral, PublicKeyToken=null' because >it contains an object field at offset 1 that is incorrectly aligned or >overlapped by a non-object field. > >WHY? reference type (such as a byte array) overlap a value type. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Yes, I'm trying to do unions, but, it freaks out when I want to have a union
with a fixed amount of data (255 bytes) and the data broken out by structures. So, I'd like to be able to to look at the data as the complete byte(255) array or by name (defined by the structures). It can be done in VC.NET but not in VB.NET??? The problem is that it thinks it overlapping when I compile, but it shouldn't care, it's either one view or another (of the same data)... do I need to use the overload method to achieve this? Danny Show quoteHide quote "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message news:eXKnfZbLGHA.3276@TK2MSFTNGP09.phx.gbl... > >System.TypeLoadException: Could not load type 'Test.Message' from > >assembly >>'Test, Version=1.0.2228.19435, Culture=neutral, PublicKeyToken=null' >>because >>it contains an object field at offset 1 that is incorrectly aligned or >>overlapped by a non-object field. >> >>WHY? > > The error message pretty much tells you why. You can't have a > reference type (such as a byte array) overlap a value type. > > > Mattias > > -- > Mattias Sjögren [C# MVP] mattias @ mvps.org > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com > Please reply only to the newsgroup.
Changing a richtextbox's colour!
Conversion question Vanishing Declarations Q: Message Box graphics .NET PDF toolkit that can compress images in PDF files..? sort treeview Changing default printer..... Windows Explorer Integration VS2005 Standard vs. VS2003.Net Academic what is the meaning of this error message? |
|||||||||||||||||||||||