Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / April 2005

Tip: Looking for answers? Try searching our database.

Aggregating .NET Com objects

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew Roberts - 28 Apr 2005 11:59 GMT
I have an object written in traditional C++ COM, it is an Apartment threaded
object, this aggregates any number of other COM objects, written in any
language capable of implementing COM.

I have encountered marshalling problems when one of the COM objects being
aggregated is written in .NET, like most traditional COM objects my outer
object does not implement IMarshal therefore the QI by the
marshaling/interop layer for this interface gets serviced by the aggregatee
written in .NET.  This effectively confuses the marshaller which now
incorrectly gets the inner objects implementation of IMarshal, which due to
all .NET COM objects behaving as if they aggregate the free-threaded
marshaller effectively makes it look like the outer object aggregates the
free threaded marshaller.  Therefore when inter apartment calls occur the
call executes on the wrong thread, the calling thread, rather than being
marshalled back onto the correct thread.  I have also had similar problem
with IProvideClassInfo/IProvideClassInfo2 where the .NET aggregates
implementation is getting incorrectly passed out.

My solution has been firstly to implement
IProvideClassInfo2/IProvideClassInfo on the outer aggregator object, which
was easy to do.  Secondly, and the part I am not so comfortable with, I have
stopped the QI for IMarshal getting serviced by the aggregates, I now just
return E_NOINTERFACE from my outer object.  Even though this works perfectly
and as expected the reason why I am uncomfortable with the fix is because I
have never seen any official documentation anywhere saying that you should
be carefull not to forward on certain interface requests.  The fix I have
done seems completely reasonable but it would be nice to have this confirmed
as being the correct solution.
"Peter Huang" [MSFT] - 29 Apr 2005 09:46 GMT
Hi Andrew,

All managed objects other than those derived from ServicedComponent, when
exposed to COM, behave as if they have aggregated the free threaded
marshaler (FTM).  In other words, they can be called on any thread without
any cross-apartment marshaling.

Although managed objects act as if they aggregate the FTM, they don¡¯t
actually aggregate it because that would be inefficient.  Instead, the CLR
implements IMarshal on behalf of all managed objects that don¡¯t provide
their own implementation.  The IMarshal implementation we provide is
similar to the one the FTM would do.

Managed objects & COM
http://blogs.msdn.com/cbrumme/archive/2003/04/15/51335.aspx

Since the .NET exposed COM's IMarshal is implemented by .NET runtime CCW, I
think your approach is valid.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.