'Object apartment vs Thread apartment

I read about apartment model, but it is still confusing me when I'm trying to understand the following: whose apartment dictates the apartment model? Is it the thread's apartment or the apartment of the created object?
Consider the following scenario:

  1. I've created C++ ATL COM dll that has only one interface which is ISimpleCom, and I have a class the implements that interface which has only one method test(); This class publicly inherit from CComObjectRootEx<CComSingleThreadModel> which sets STA apartment.

  2. Reference this DLL in C# WinForms project, and create the SimpleCom object on a MTA thread (not the UI thread). The question is: Lets say UI thread call test() on this object, will it be marshaled to the thread created the object or it will be executed on the UI thread ?

    • If it follows the object COM apartment this call should be marshaled to the thread who created the object because it is an STA object.
    • If it follows creating thread apartment which is MTA, it should be executed on the UI thread.

Which one is the correct one?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source