Multi Threaded DLL Call

I had to write a .Net DLL as a wrapper for System.IO.Ports.SerialPort object as a result of some marshaling limitations in AX 4 for .Net complex types.

When I try to call the DLL, I get some error about ‘Clr Interop Marshal: Unsupported type.’

If I remove all the code out of the method in the DLL and just return a string, everything works perfectly so I know it’s not in how I’m calling the class/method.

My question is this: I’m using an AutoResetEvent object to keep some things in the thread synchronized, and I think the problem results because of this issue. Can anyone confirm whether calling multi-threaded DLL’s from AX 4 causes problems?

Addendum: I found out the Unsupported type error was unrelated, it was the result of poor exception handling.

However, when I keep the AutoResetEvent in the DLL it causes AX to crash when calling. If I remove that code, then AX can successfully call the DLL.

Please note the code is tested in a .Net native application and works without issue. It’s only when calling from AX that it causes crashes.