Closed
Description
Today, I have finally found the reason, why my DBus implementation works with Mono, but doesn't with .NET Core:
System.TypeLoadException: Cannot marshal field 'control' of type 'msghdr': Unknown error.
at System.StubHelpers.ValueClassMarshaler.ConvertToNative(IntPtr dst, IntPtr src, IntPtr pMT, CleanupWorkList& pCleanupWorkList)
at Dbus.Connection.recvmsg(IntPtr sockfd, msghdr& buf, Int32 flags)
at Dbus.Connection.receive()
Here's a quick copy of the code from here
[DllImport("libc")]
private static extern int recvmsg(IntPtr sockfd, [In] ref msghdr buf, int flags);
private unsafe struct iovec
{
public byte* iov_base;
public int iov_len;
}
private unsafe struct msghdr
{
public IntPtr name;
public int namelen;
public iovec* iov;
public int iovlen;
public int[] control;
public int controllen;
public int flags;
}
When calling recvmsg
, Mono is fine with marshalling the control
member of msghdr
. For .NET Core (1.1 and 2.0-preview2), I had to change int[]
to int*
and add another fixed statement to my code.
The Unknown error
makes me wonder if there's something missing in .NET Core.