471,620 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,620 software developers and data experts.

marshaling:SizeOf(object structure) error


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[] StructureToBytesArray(object obj)
int len = Marshal.SizeOf(obj);
byte[] arr = new byte[len];
IntPtr ptr = Marshal.AllocHGlobal(len);
Marshal.StructureToPtr(obj, ptr, true);
Marshal.Copy(ptr, arr, 0, len);
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 = StructureToBytesArray(pkt[j]);

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

thanks in advance
Apr 6 '08 #1
0 1029

Post your reply

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

Similar topics

reply views Thread by Yuri | last post: by
reply views Thread by Marquee | last post: by
2 posts views Thread by Pas de Spam | last post: by
reply views Thread by Rodger Brennan | last post: by
3 posts views Thread by Sin | last post: by
2 posts views Thread by Laurent | last post: by
5 posts views Thread by =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post: by

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.