Instead of the .NET Framework CLR I tried the much more advanced .NET Core CLR and that doesn't run the slow function but throws:
System.ExecutionEngineException: 'Exception of type 'System.ExecutionEngineException' was thrown.'
edit:
with native code debugging enabled:
Exception thrown at 0x00007FF80C2C2EE8 (coreclr.dll) in cs console.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
edit2:
difference is the fast variant calls AddRef in the QueryInterface method.
edit3:
the solution:
Code:
__declspec(dllexport) LPVOID __stdcall
CreateBasicServerSlow()
{
auto value = new BasicServer();
value->AddRef();
return value;
}