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

10,305

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

Share:
10,305
mmpatel009
Author by

mmpatel009

Updated on June 05, 2022

Comments

  • mmpatel009
    mmpatel009 almost 2 years

    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.