I am a C++ developer so I do not have much experience with C#, however, I have to fix this problem anyway.
There is a C# GUI which is using some C++ DLLs. When calling one of the methods from one of the DLLs a System.ExecutionEngineException occurs. Obviously I cant step into the C++ code to see if there is a problem with this code. So I build a small C++ testing application and this one worked fine. The parameters the method is called with in the C# code also look fine to me (used the same values in my C++ testing app). Although there is a problem somewhere in the GUI which may or may not be related to this issue, the same executable started without Visual Studio works just fine.
I have currently no idea on how to find out what causes the problem. Any hints will be highly appreciated.
Call to method in C# code where caseID is of type int, paramID is of type System.Int32 and paramData is a custom struct.
getParameter(caseID, dataID, paramID, ref paramData)
The signature of the method in the C# code looks like this:
[ DllImport ("helper.dll", CallingConvention=CallingConvention.Cdecl/*, CharSet = CharSet.Auto*/ )]
public static extern ERROR getParameter(System.Int32 caseID, System.Int32 dataID, System.Int32 paramID, ref PARAMETER_DATA data);
The signature of the corresponding method in the C++ DLL looks like this:
ERROR _stdcall getParameter(const long caseID, const long dataID, long number, PARAMETER_DATA *data);
What does look odd to me is that the C++ code explicitly states that the method should be called with calling convention “stdcall” whereas the C# code want to use Cdecl. However, this code seems to have worked for quite a while now. I also tried to change both calling conventions to stdcall but that did not work either.
The problem was that a struct member which is a char[] in C++ changed its size. In the C# code there was this attribute
So I had to change the value of the SizeConst property. Don’t know why I didn’ see this when I first checked the structs for differences…
I also fixed the calling convention issue and now everything seems to work fine.