Search code examples
c#c++dllunhandled-exceptionexecutionengineexception

An unhandled exception of type 'System.ExecutionEngineException' occurred in XXX.exe


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.


Solution

  • 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