By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,110 Members | 1,537 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,110 IT Pros & Developers. It's quick & easy.

Interop service error: Cannot marshal field 'XXX' of type 'XXX': There is no marshaling support for this type.

P: n/a
I'm trying to call my DLL written in C, and got the error:

Cannot marshal field 'b' of type 'mystruct': There is no marshaling
support for this type.

The 2 functions in the DLL are:

void unpack(mystruct* str, void* in_buf);
void pack(mystruct* str, void* out_buf);

The data structure is as follows:

typedef struct
{
byte a;
} struct_a;

typedef struct
{
byte a;
byte b[15];
} struct_b;

typedef struct
{
byte a;
union
{
struct_a b;
struct_b c;
};
} struct_c;

typedef struct
{
byte a;
struct_c b[15];
struct_c c[15];
} mystruct;

My type definition in C# is:

public class PRLCodec
{
[DllImport("my.dll")]
public extern static void unpack(
out mystruct str,
IntPtr buf);

[DllImport("my.dll")]
public extern static void pack(
ref mystruct str,
IntPtr buf);

}

[StructLayout(LayoutKind.Sequential)]
public struct struct_a
{
byte a;
}

[StructLayout(LayoutKind.Sequential)]
public struct struct_b
{
byte a;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=15)]
byte[] b;
}

[StructLayout(LayoutKind.Explicit)]
public struct struct_c
{
[FieldOffset(0)]
byte a;
[FieldOffset(1)]
struct_a b;
[FieldOffset(1)]
struct_b c;
}

[StructLayout(LayoutKind.Sequential)]
public struct mystruct
{
byte a;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
mystruct[] b;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
mystruct[] c;
}

The code compiles but gives the above error. What could be wrong? I
tried to read documents on interop service, but it seemed overwhelming
to a new .NET programmer. Any help is appreciated.

Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.