Consider the following interface (registered with regasm /tlb
with a c# out of process server and client):
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IComTestTarget
{
InterestingRecord[] GetInterestingRecords();
}
[ComVisible(true)]
public struct InterestingRecord
{
public Guid guid;
[MarshalAs(UnmanagedType.BStr)]
public string ChatText;
}
If I try to call GetInterestingRecords
, I receive an exception in the server process:
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at GetRecordInfoFromTypeInfo
at OleVariant::CreateSafeArrayDescriptorForArrayRef
at System.StubHelpers.MngdSafeArrayMarshaler.ConvertSpaceToNative
If I comment out the line public Guid guid;
or if I comment the line [MarshalAs(UnmanagedType.BStr)] public string ChatText;
, the call completes as expected. If I change the interface to return a single value rather than an array, the call completes as expected. What am I doing wrong?
Runnable minable example at GitHub
User contributions licensed under CC BY-SA 3.0