C# COM Interop code that works with mono 3.0.12 and earily now causes crashes with mono 3.1.1 and newer. (I've tested up to mono 3.2.8)
Caused by the following commit:
Author: Rodrigo Kumpera <email@example.com>
Date: Fri Jun 21 20:31:02 2013 -0400
When compiling gshared code, always use the cached isinst/castclass as it's faster than the cached one.
It difficult to provide a small self contained test case, but I will attempt to describe the crash:
Give a COM object, SomeComObject, that implements in interfaces IOne and ITwo, where IOne has a SomeMethod method;
The first time code like this is executed:
IOne someComObject = ....;
The C++ COM objects SomeMethod is correctly called.
However if this same code is re-executed a second time on a different instance of SomeComObject, the call to someComObject.SomeMethod(); crashes. (somewhere in the emitted marshing code, it looks like).
What seems to be happening is that for the second call, mono is incorrectly attempting to call a method on ITwo.
On a test mono build I've reversed the patch for e3866aa09217c5fe86ef9fe8d3bba3a618bc3ec5 and it fixes the crash.
You can also run mono with -O=-gshared as a workaround.
Does -O=-gshared fix for you?
Yes - Settings -O=-gshared does indeed prevent the crash.
This does appear to be a workaround however rather than fixing the bug.