473,785 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

marshaling:Size Of(object structure) error

16 New Member
hi,

the following marshaling code gives me an errror of "type packet cannot be marshaled as an unmanaged structure; no meaningful size or offset can be managed".

public static byte[] StructureToByte sArray(object obj)
{
int len = Marshal.SizeOf( obj);
byte[] arr = new byte[len];
IntPtr ptr = Marshal.AllocHG lobal(len);
Marshal.Structu reToPtr(obj, ptr, true);
Marshal.Copy(pt r, arr, 0, len);
Marshal.FreeHGl obal(ptr);
return arr;
}
.
.
.
.
.
this is the structure i am trying to marshal an send thru the socket:

public struct packet
{
public string data;
public string D;
public string SD;
public string PD1;
public string SPD1;
public int[] SBD1;
public int[,] SBD2;

}

.
.
.
byte[] str = StructureToByte sArray(pkt[j]);

i am getting an error for the Marshal.SizeOf( object structure).kind ly help...


thanks in advance
Apr 6 '08 #1
0 1155

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2183
by: Yuri | last post by:
Hello everyone. I'm trying to use CopyMemory API in VB.NET. I have a module with struct defined like this: <StructLayout(LayoutKind.Sequential)> _ Public Structure tSortKey <VBFixedString(6), System.Runtime.InteropServices.MarshalAs (System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=6)> Public CorpNum As Char()
0
1227
by: Marquee | last post by:
Hello, When I try to implement a custom marshaler I get an exception when the Marshal.SizeOf() method is invoked. The message is: "Type MyNS.PT_DATAFRAME can not be marshaled as an unmanaged structure; no meaningful size or offset can be computed." Is custom marshaling possible with a struct? Perhaps a better question is help, what am I doing wrong here?
2
1875
by: Pas de Spam | last post by:
Hi, I have some problem in marshaling array of structure. I have to exchange a structure of data with a C++ program. This structure data contains a field which is an array of a custom type. I can't find the correct sequence to declare the marshal attributes of my structures, I always got an exception at runtime when marshaling my data. Here an example of code, which gives me the exception "Type TypeData can not be marshaled as an...
0
13894
by: Rodger Brennan | last post by:
I'm tring to implement the ObjectPicker for a project I'm working on. I'm using the DSObjectPickerWrapper found at http://dotnet.org.za/armand/articles/2453.aspx This works fine as is, but I need to get additional Attributes back from the Picker specifically "objectSid" Unfortunately, I can figure out how to marshal the initInfo.apwzAttributeNames Property. In the API documention for the ObjectPicker, it is defined as a PCWSTR data...
3
2340
by: Sin | last post by:
Hello everybody, I'm currently trying to understand how marshaling can use used for accessing Win32 API functions as well as custom C/C++ code we design which exposes functions the same way as the Win32 API. I figured how to use strings... No problem there, there was a couple undred examples on the net. I have yet to find how to do the same with an array of integers for example... Here's my test code :
2
1962
by: Laurent | last post by:
Hi again, I created a thread some days ago, while I was trying to access a C++ DLL using my C# program. First of all, I want to thanks all the guys who helped me. But I still have a problem... My C++ DLL has a function which has the following prototype: long FF_Function(void* inInstance, char* inDate, FF_Struct**
6
5900
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example will prove useful. structure MyStruct { // this is a complicated struct declaration in the sense
0
1878
by: jpogorman | last post by:
Hello, I am trying to get c# custom marshaling working in a particular scenario but it does not appear to be working or not jumping into my marshaling class when I try to debug it. I am try to implement a performance improvement in the transfer of thousands of objects (ClientInfoDescriptor) over a remote call. The objects all have a model object (IDataDrivenModel) to describe them but there may only two or three model objects in total. These...
5
3797
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);" I thought that it is very hard to memory map structure array. I need both read and write memory mapped file at both side of C# and C++.
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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
10147
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
10091
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
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
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
5381
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.