[Mono-list] Interop problem: ** ERROR **: Type System.MarshalByRefObject which is passed to unmanaged code must have a StructLayout attribute
Frederik Carlier
frederik.carlier at ugent.be
Sat Feb 24 16:06:21 EST 2007
Hi all,
I have, unfortunately, another Interop problem with Mono. Using a struct
like this:
[StructLayout(LayoutKind.Sequential)]
internal struct StreamSource
{
private TidyBuffer buffer;
private Stream stream;
}
, I have the following code:
StreamSource data = new StreamSource();
data.stream = stream;
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(data));
Marshal.StructureToPtr(data, ptr, true);
which runs fine on Windows and Microsoft .NET, but crashes badly on Mono:
** ERROR **: Type System.MarshalByRefObject which is passed to unmanaged
code must have a StructLayout attribute
aborting...
Stacktrace:
at (wrapper managed-to-native)
System.Runtime.InteropServices.Marshal.StructureToPtr
(object,intptr,bool) <0x00004>
at (wrapper managed-to-native)
System.Runtime.InteropServices.Marshal.StructureToPtr
(object,intptr,bool) <0xffffffff>
at (...)
So, obviously, the question is: what am I doing wrong, if anything?
Thanks in advance!
Frederik.
More information about the Mono-list
mailing list