Due to company constraints out of my control, I have the following scenario:
A COM library that defines the following interface (no CoClass, just the interface):
[ object, uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx), dual, nonextensible, helpstring('IService Interface'), pointer_default(unique) ] IService : IDispatch { HRESULT DoSomething(); } [ object, uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx), dual, nonextensible, helpstring('IProvider Interface'), pointer_default(unique) ] IServiceProvider : IDispatch { HRESULT Init( IDispatch *sink, VARIANT_BOOL * result ); HRESULT GetService( LONG serviceIndicator, IService ** result ); }; [ uuid(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx), version(1.0), ] library ServiceLibrary { importlib('stdole2.tlb'); interface IService; interface IServiceProvider; };
I have a COM (written w/ C++) that implements both interfaces and provides our application(s) with said service. All is fine, I think.
I’m trying to build a new IProvider and IService in .NET (C#).
I’ve built a Primary Interop Assembly for the COM library, and implemented the following C#:
[ComVisible( true )] [Guid( 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' )] public interface INewService : IService { // adds a couple new properties } [ComVisible( true )] [Guid( 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' )] public class NewService : INewService { // implement interface } [ComVisible( true )] [Guid( 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' )] public interface INewProvider : IServiceProvider { // adds nothing, just implements } [ComVisible( true )] [Guid( 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' )] public class NewProvider : INewProvider { // implement interface }
When I attempt to slip this into the existing runtime, I am able to create the NewProvider object from COM (C++), and QueryInterface for IServiceProvider. When I attempt to call a method on the IServiceProvider, a System.ExecutionEngineException is thrown.
The only other thing I can find, is by looking at the .tlh files created by the #import, shows the legacy COM IExistingProvider class correctly shows that it is derived from IServiceProvider. However the .NET class shows a base of IDispatch. I’m not sure if this a sign, indication, helpful, something else.
It could be a problem with the name IServiceProvider. Check that you haven’t already imported an interface with the same name.
When I create an COM Interface library using your IDL, and then try to import it from another client, I get the warning:
Otherwise, you can try renaming it to IServiceProvider2. That’s what I did, and everything works fine. I’m using Visual Studio 2008.
If this code runs properly on your machine (it works perfectly on mine) then the problem could be in your implementation.
IDL:
C#:
C++ Client: