It is my understanding building a COM object aggregating an existing COM object implies implementing redirection logic in the IUnknown.QueryInterface method of the outer object.
The question I have is how to do that if the object you are building is managed. On managed objects IUnknown is not explicitly implemented COM Interop does it for you. So how do I tell COM Interop that the object I build is an aggregation of another COM object?
So far the only way I found is to implement all the interfaces of the inner object on the outer and explicitly redirect them. This is a) ugly and b) assumes that you know all the interfaces to implement which is not the case in my situation.
Any thoughts?
If you are using .NET 4 then you could use ICustomQueryInterface to override the default
IUnknown.QueryInterface
logic. There's a sample for COM aggregation on CodePlex - the implementation is quite straightforward: