OK - I thought I better check this to ensure they didn't break it since 1.0 alpha (I tested it out then as I was teaching Essential COM in those days).
I just wrote an MTA COM object which took a BSTR as a parameter ( non-blittable) and called it from an application with the STAThread attribute on the Main. So both the Interop and the COM marshaller were involved. Works fine.
I've seen a couple of posts over the last few months that seemed to suggest that performing cross-apartment calls from managed code to unmamaged code wasn't supported. I thought I was maybe just misreading what they were saying and so let it pass. But there is, it seems, some currency in the idea that it doesn't work
There is not just one marshalling layer in place. The RCW uses the interop layer to get into the COM type system and then the COM marsaller (in my case the universal marshaller) builds the COM marshalling info for cross apartment invocation. The object is invoked, then COM marshals the call back to the STA (in my example) and the RCW managed the transition back to the CLR type system.
The crucial reason why you want to use the same apartment type when invoking COM objects is to remove the need for the COM marshalling layer which adds a non-trivial overhead with "chatty" interfaces (ones which perform alot of calls having, say, lots of properties on them).
ActiveX controls have other issues as they are UI code. Its not specifically that they are STA based.
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<e5**************@TK2MSFTNGP12.phx.gbl>
Hey, come on, I didn't make the technology!
When the ApartmentState(s) differ between Com and .Net components and
the communication has to happen across processes then marshalling has to
be adopted, right? In the case of different apartment states,
marshalling is taken care of by the underlying platform to some extent -
the extent being that if the apartment states are similar then the CLR's
Interop Marshaler can take care of most of the marshalling unless there
are non-blittable types involved in which case you need to use the
MarshalAs attribute to solve the purpose. In case of differing apartment
state(s), the COM Interop marshaler takes over and hence, there was an
error as the COM marhaller does not know .Net types.
But, since the Windows Application (in V.Net) inserts a Main method with
a [STAThread] attribute the apartment states are equalized and hence, no
error for the OP.
I hope this answer satisfies your incredulity!