[cominterop] Attach to runtime from IUnknown and IDispatch methods (mono/mono#18175)
* [cominterop][test] Calling QueryInterface from an unattached thread asserts
If we pass a managed COM object to native code and the native code calls one of
the IUnknown methods, we assert because the thread is not attached but we want
to enter GC Unsafe mode.
* [cominterop] Attach to runtime from IUnkown and IDispatch methods
If the COM objects for a managed object is passed to a thread that hasn't
interacted with Mono before, we need to attach before doing GC thread state
transitions.
Addresses https://github.com/mono/mono/issues/18137
* [test] Call managed method through COM wrapper from unattached thread
This works, but I don't think we had a test previously. Call a managed method
via a COM interface from a thread that is not attached to the runtime, to
ensure that it is attached.
Commit migrated from https://github.com/mono/mono/commit/
d0f27ce4feb07bdcf7958272e6e943eb2a2f0f7b