468,769 Members | 2,201 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,769 developers. It's quick & easy.

marshaling:SizeOf(object structure) error

16
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[] 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);
Marshal.FreeHGlobal(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 = StructureToBytesArray(pkt[j]);

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


thanks in advance
Apr 6 '08 #1
0 967

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
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.