B
Betty
When marshalling a char array in a structure from C to .NET, I get the
following error:
System.ArgumentException: Type could not be marshaled because the
length of an embedded array instance does not match the declared
length in the layout.
namespace RemoteClientNew
{
[StructLayout(LayoutKind.Sequential)]
public struct contacts
{
[MarshalAs UnmanagedType.ByValArray,
ArraySubType=UnmanagedType.AnsiBStr, SizeConst=10)] public byte[]
name;
public int age;
public int id;
}
}
The name field in C code also has a size of 10.
Trying using UnmanagedType as LPArray or ByValTStr with CharSet.Ansi
gives the following error:
System.TypeLoadException: Can not marshal field name of type
RemoteClientNew.con
tacts: This type can not be marshaled as a structure field.
following error:
System.ArgumentException: Type could not be marshaled because the
length of an embedded array instance does not match the declared
length in the layout.
namespace RemoteClientNew
{
[StructLayout(LayoutKind.Sequential)]
public struct contacts
{
[MarshalAs UnmanagedType.ByValArray,
ArraySubType=UnmanagedType.AnsiBStr, SizeConst=10)] public byte[]
name;
public int age;
public int id;
}
}
The name field in C code also has a size of 10.
Trying using UnmanagedType as LPArray or ByValTStr with CharSet.Ansi
gives the following error:
System.TypeLoadException: Can not marshal field name of type
RemoteClientNew.con
tacts: This type can not be marshaled as a structure field.