ExecutionEngineException thrown when marshalling interface array from .Net to C++
I have the following COM interface that I have implemented in C#:
[InterfaceType(1)]
[TypeLibType(256)]
public interface 开发者_开发知识库IEnumMyType
{
void Clone(out IEnumMyType ppEnum);
void RemoteNext(uint celt, IMyType[] rgelt, out uint pCeltFetched);
void Reset();
void Skip(uint celt);
}
However when the RemoteNext
method is called from C++ the following exception is thrown:
An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.
This is the C++ code that calls this interface.
CComPtr<IEnumMyType> spEnum;
CComPtr<IMyType> spElem;
ULONG iElemCount = 0;
/* Creation of spEnum skipped */
spEnum->Next(1, &spElem, &iElemCount);
It seems like the managed COM interface declaration is incorrect but it was generated by Tlbexp.exe.
Whats going on?
Is there anymore information on the rgelt parameter (potentially a MarshalAsAttribute)? Without some additional attributes, COM Interop marshaling will default marshal arrays as SAFEARRAYS. You are not passing a safe array for this parameter when calling it, which could be a problem.
精彩评论