3

I have a DLL file that is written in C++. I am try to use in C++ DLL in my c# code. C++ method is called correctly but it gives error after process completed.

Exception Details:

completed.System.ExecutionEngineException was unhandled Message=Exception of type 'System.ExecutionEngineException' was thrown.

mmpatel009
  • 921
  • 4
  • 11
  • 25
  • It would help if you could show us the `Message` and `StackTrace` fields of the `ExecutionEngineException`. http://msdn.microsoft.com/en-sg/library/system.executionengineexception.aspx – John Zwinck Apr 10 '13 at 12:33
  • do you have a debug version of the C++ dll? if yes you can debug it. You can also use Microsoft Debugging Tools for windows to create an application dump. – Siraf Apr 10 '13 at 16:58
  • 1
    This usually means that there is a memory corruption bug in the unmanaged DLL, and it is corrupting the engine. – Raymond Chen Apr 11 '13 at 14:09

1 Answers1

0

I got the same problem with this code:

    [DllImport("camapi.dll", CharSet = CharSet.Unicode)]
private static extern CSTATUS_T CWRAPPER_GetFriendlyName(IntPtr pCameraBus, string sCamID, out StringBuilder sFriendlyName, 
                                                         uint uBufferSizeInWords);

public static string CWRAPPER_GetFriendlyName(IntPtr pCameraBus, string sCamID)
{
    var sFriendlyName = new StringBuilder(256);
    var status = CWRAPPER_GetFriendlyName(pCameraBus, sCamID, out sFriendlyName, (uint)s.Capacity + 1);
    return (status == CSTATUS_T.CSTATUS_SUCCESS) ? sFriendlyName.ToString() : "";
}

The problem was the "out" keyword. The example on MSDN doesn't have the 'out'.

Hope that helps someone... Simon

Simon
  • 379
  • 6
  • 10