473,657 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Structures using FieldOffset -- BUG?

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.TypeLoad Exception: Could not load type 'Test.Message' from assembly
'Test, Version=1.0.222 8.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(L ayoutKind.Expli cit)> _
Public Structure R_OMNI_LINK_MES SAGE
<FieldOffset(0) > Public MessageLength As Byte
' ....... THIS ONE DOESN'T WORK!!.... Throws Error
<FieldOffset(1) , MarshalAs(Unman agedType.ByValA rray, 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_DA TA
<FieldOffset(2) > Public COMMAND_MESSAGE As olmCOMMAND_MESS AGE
<FieldOffset(2) > Public SET_TIME As olmSET_TIME
<FieldOffset(2) > Public SYSTEM_STATUS As olmSYSTEM_STATU S
<FieldOffset(2) > Public REQUEST_ZONE_ST ATUS As olmREQUEST_ZONE _STATUS
<FieldOffset(2) > Public REQUEST_UNIT_ST ATUS As olmREQUEST_UNIT _STATUS '8bit
/ 16bit
<FieldOffset(2) > Public REQUEST_AUXILIA RY_STATUS As
olmREQUEST_AUXI LIARY_STATUS
<FieldOffset(2) > Public REQUEST_THERMOS TAT_STATUS As
olmREQUEST_THER MOSTAT_STATUS
<FieldOffset(2) > Public LOGIN As olmLOGIN
<FieldOffset(2) > Public REQUEST_SECURIT Y_CODE_VALIDATI ON As
olmREQUEST_SECU RITY_CODE_VALID ATION
<FieldOffset(2) > Public SECURITY_CODE_V ALIDATION As
olmSECURITY_COD E_VALIDATION
End Structure


Feb 9 '06 #1
4 5906
Quick update... If I change the StructLayout to
<StructLayout(L ayoutKind.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" <ne**@mavromati s.com> wrote in message
news:11******** *****@corp.supe rnews.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.TypeLoad Exception: Could not load type 'Test.Message' from assembly
'Test, Version=1.0.222 8.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(L ayoutKind.Expli cit)> _
Public Structure R_OMNI_LINK_MES SAGE
<FieldOffset(0) > Public MessageLength As Byte
' ....... THIS ONE DOESN'T WORK!!.... Throws Error
<FieldOffset(1) , MarshalAs(Unman agedType.ByValA rray, 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_DA TA
<FieldOffset(2) > Public COMMAND_MESSAGE As olmCOMMAND_MESS AGE
<FieldOffset(2) > Public SET_TIME As olmSET_TIME
<FieldOffset(2) > Public SYSTEM_STATUS As olmSYSTEM_STATU S
<FieldOffset(2) > Public REQUEST_ZONE_ST ATUS As olmREQUEST_ZONE _STATUS
<FieldOffset(2) > Public REQUEST_UNIT_ST ATUS As olmREQUEST_UNIT _STATUS
'8bit
/ 16bit
<FieldOffset(2) > Public REQUEST_AUXILIA RY_STATUS As
olmREQUEST_AUXI LIARY_STATUS
<FieldOffset(2) > Public REQUEST_THERMOS TAT_STATUS As
olmREQUEST_THER MOSTAT_STATUS
<FieldOffset(2) > Public LOGIN As olmLOGIN
<FieldOffset(2) > Public REQUEST_SECURIT Y_CODE_VALIDATI ON As
olmREQUEST_SECU RITY_CODE_VALID ATION
<FieldOffset(2) > Public SECURITY_CODE_V ALIDATION As
olmSECURITY_COD E_VALIDATION
End Structure

Feb 9 '06 #2
More updates: Changing it to Auto isn't what I need since the fieldoffsets,
don't seem to be doing anything with Auto.

"Danny Mavromatis" <ne**@mavromati s.com> wrote in message
news:11******** *****@corp.supe rnews.com...
Quick update... If I change the StructLayout to
<StructLayout(L ayoutKind.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" <ne**@mavromati s.com> wrote in message
news:11******** *****@corp.supe rnews.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.TypeLoad Exception: Could not load type 'Test.Message' from
assembly
'Test, Version=1.0.222 8.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(L ayoutKind.Expli cit)> _
Public Structure R_OMNI_LINK_MES SAGE
<FieldOffset(0) > Public MessageLength As Byte
' ....... THIS ONE DOESN'T WORK!!.... Throws Error
<FieldOffset(1) , MarshalAs(Unman agedType.ByValA rray, 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_DA TA
<FieldOffset(2) > Public COMMAND_MESSAGE As olmCOMMAND_MESS AGE
<FieldOffset(2) > Public SET_TIME As olmSET_TIME
<FieldOffset(2) > Public SYSTEM_STATUS As olmSYSTEM_STATU S
<FieldOffset(2) > Public REQUEST_ZONE_ST ATUS As olmREQUEST_ZONE _STATUS
<FieldOffset(2) > Public REQUEST_UNIT_ST ATUS As olmREQUEST_UNIT _STATUS
'8bit
/ 16bit
<FieldOffset(2) > Public REQUEST_AUXILIA RY_STATUS As
olmREQUEST_AUXI LIARY_STATUS
<FieldOffset(2) > Public REQUEST_THERMOS TAT_STATUS As
olmREQUEST_THER MOSTAT_STATUS
<FieldOffset(2) > Public LOGIN As olmLOGIN
<FieldOffset(2) > Public REQUEST_SECURIT Y_CODE_VALIDATI ON As
olmREQUEST_SECU RITY_CODE_VALID ATION
<FieldOffset(2) > Public SECURITY_CODE_V ALIDATION As
olmSECURITY_COD E_VALIDATION
End Structure


Feb 9 '06 #3
>System.TypeLoa dException: Could not load type 'Test.Message' from assembly
'Test, Version=1.0.222 8.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.
Feb 9 '06 #4
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
"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:eX******** ******@TK2MSFTN GP09.phx.gbl...
System.TypeLoa dException: Could not load type 'Test.Message' from
assembly
'Test, Version=1.0.222 8.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.

Feb 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1120
by: Johnny Lee | last post by:
Hi, I've met a problem while using anygui to create a GUI. Here is a brief example from Dave: ### def guidialog(): def ok(**kw): win.destroy() app.remove(win) #<snip>
1
1649
by: ½Éº¸ÁØ | last post by:
Hello guys. I have a problem in using a public static library. The library file name is libminipar.a and it was written in c++. For using the public library, I first wrote test.c(and test.cpp) which included following. // test.c ////////////////////////////////////////// #include "ptree.h" //library header file int main() {
6
1659
by: lgn | last post by:
I have test the following program, why the result is not 0 2 4 but 0 2 3? Can someone tell me why the same macro produce different result? Thanks! #include <stdio.h> #define max(a,b) ((a)>(b) ? (a): (b)) test() { printf("%d\n", 1); }
2
2357
by: TaeHo Yoo | last post by:
Have a problem with using cursors in SQL server enterprise manager. My code sql query is followed --------------------------------------- DECLARE @element_name varchar(100) DECLARE elements_cursor CURSOR FOR SELECT element_name FROM KB_Element_Ref OPEN elements_cursor FETCH NEXT FROM elements_cursor INTO @element_name
1
5862
by: Anup | last post by:
In my form I and doing validations using 'Javascript' as I m using ASP1.1 and there is very less support for Validators there. //Code Behind private void Page_Load(object sender, System.EventArgs e) { Button1.Attributes.Add("OnClick","fun()"); } Problem in using "Button1.Attributes.Add " for client side script for
2
2021
by: bienwell | last post by:
Hi all, I still have a problem when using Confirmation box in ASP.NET program. I need to get the value return of YES or NO from confirmation box in Sub function of VB program to do some tasks. For example, I have 2 text boxes and one button. The button will call On_Click event . Sub btnSelect_OnClick(ByVal sender As Object, ByVal e As EventArgs) Dim X as double = CDBL(txtbox1.text) Dim Y as double = CDBL(txtbox2.text)
6
1650
by: palani12kumar | last post by:
hi everybody... I've a problem in using system() functions. my program was: int main() { clrscr() system("dir"); getch(); }
2
2897
by: apoorva.groups | last post by:
Hi I am facing problem while using regexec function. Ex: String = "abc_def_hig" sub string = "def" regexc if I use regexec the it will find the sub string in string and it will return 0. I want to modify the sub string such that it matches only if the
0
1693
by: Developer111 | last post by:
Hi, I converted a VB6 application in VB.net 2008 by using VS 2008 conversion wizard I have encountered a problem in using Tab control in VB.net. I used “Microsoft TabStrip Control 6.0 (SP6)” in VB 6 project. VB.net converter wizard converted it properly and add reference to “AxInterop.MSComctlLib.dll” and “Interop.MSComctlLib.dll”. I am using TabStrip on a Form that is use “Hide” instead of “Close”. So problem is when this form shown again...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.