Hi,
I'm trying to marshal data from a C API. The struct contains an array of
structs. The Marshal.PtrToStructure call throws a TypeLoadException with the
message - "Can not marshal field struct_arr of type NODE: This type can not
be marshaled as a structure field."
Changing from an array of structs to an array of blittable types works.
Is it possible to marshal an array of structs?
[StructLayout(LayoutKind.Sequential), ComVisible(false)]
public struct NODE
{
public uint id;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=3 )]
public byte[] byte_arr;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=3 )]
public FOO[] struct_arr;
}
[StructLayout(LayoutKind.Sequential), ComVisible(false)]
public struct FOO
{
public ulong val;
public byte state;
}

Signature
Thanks,
-Robin
Mattias Sjögren - 13 Sep 2006 05:05 GMT
>I'm trying to marshal data from a C API. The struct contains an array of
>structs. The Marshal.PtrToStructure call throws a TypeLoadException with the
>message - "Can not marshal field struct_arr of type NODE: This type can not
>be marshaled as a structure field."
This should work on .NET Framework 2.0. It wasn't supported in 1.x.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
RobinC - 13 Sep 2006 16:25 GMT
A good reason to upgrade! Thanks.

Signature
Thanks,
-Robin
> >I'm trying to marshal data from a C API. The struct contains an array of
> >structs. The Marshal.PtrToStructure call throws a TypeLoadException with the
[quoted text clipped - 4 lines]
>
> Mattias