Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 56959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:36:58+00:00 2026-05-10T17:36:58+00:00

Due to company constraints out of my control, I have the following scenario: A

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:36:59+00:00Added an answer on May 10, 2026 at 5:36 pm

    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:

    Warning 65  warning C4192: automatically excluding 'IServiceProvider' while importing type library 'ServiceLibrary.dll' 

    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:

    import 'oaidl.idl';  [     object,     uuid(9219CC5B-31CC-4868-A1DE-E18300F73C43),     dual,     nonextensible,     helpstring('IService Interface'),     pointer_default(unique) ] interface IService : IDispatch {   HRESULT DoSomething(void); }  [     object,     uuid(9219CC5B-31CC-4868-A1DE-E18300F73C44),     dual,     nonextensible,     helpstring('IProvider Interface'),     pointer_default(unique) ] interface IServiceProvider2 : IDispatch {   HRESULT Init( IDispatch *sink, VARIANT_BOOL * result );   HRESULT GetService( LONG serviceIndicator, IService ** result ); };  [     uuid(9219CC5B-31CC-4868-A1DE-E18300F73C45),     version(1.0), ] library ServiceLibrary {     importlib('stdole2.tlb');      interface IService;     interface IServiceProvider2; }; 

    C#:

    using System.Runtime.InteropServices; using System.Windows.Forms; using ServiceLibrary; using IServiceProvider=ServiceLibrary.IServiceProvider2;  namespace COMInterfaceTester {     [ComVisible(true)]     [Guid('2B9D06B9-EB59-435e-B3FF-B891C63108B2')]     public interface INewService : IService     {         string ServiceName { get; }     }      [ComVisible(true)]     [Guid('2B9D06B9-EB59-435e-B3FF-B891C63108B3')]     public class NewService : INewService     {         public string _name;          public NewService(string name)         {             _name = name;         }          //  implement interface         #region IService Members          public void DoSomething()         {             MessageBox.Show('NewService.DoSomething');         }          #endregion          public string ServiceName         {             get { return _name; }         }     }      [ComVisible(true)]     [Guid('2B9D06B9-EB59-435e-B3FF-B891C63108B4')]     public interface INewProvider : IServiceProvider     {         //  adds nothing, just implements     }      [ComVisible(true)]     [Guid('2B9D06B9-EB59-435e-B3FF-B891C63108B5')]     public class NewProvider : INewProvider     {         //  implement interface         public void Init(object sink, ref bool result)         {             MessageBox.Show('NewProvider.Init');         }          public void GetService(int serviceIndicator, ref IService result)         {             result = new NewService('FooBar');             MessageBox.Show('NewProvider.GetService');         }     } }     

    C++ Client:

    #include 'stdafx.h' #include <iostream> #include <atlbase.h> #import 'COMInterfaceTester.tlb' raw_interfaces_only #import 'ServiceLibrary.dll' raw_interfaces_only  using std::cout;  int _tmain(int argc, _TCHAR* argv[]) {     CoInitialize(NULL);   //Initialize all COM Components     COMInterfaceTester::INewProviderPtr pNewProvider(__uuidof(COMInterfaceTester::NewProvider));     ServiceLibrary::IServiceProvider2 *pNewProviderPtr;      HRESULT hr = pNewProvider.QueryInterface(__uuidof(ServiceLibrary::IServiceProvider2), (void**)&pNewProviderPtr);      if(SUCCEEDED(hr))     {                VARIANT_BOOL result = VARIANT_FALSE;         int *p = NULL;          hr = pNewProviderPtr->Init((IDispatch*)p, &result);          if (FAILED(hr))         {             cout << 'Failed to call Init';         }          ServiceLibrary::IService *pService = NULL;         hr = pNewProviderPtr->GetService(0, &pService);          if (FAILED(hr))         {             cout << 'Failed to call GetService';         }         else         {             COMInterfaceTester::INewService* pNewService = NULL;             hr = pService->QueryInterface(__uuidof(COMInterfaceTester::INewService), (void**)&pNewService);              if (SUCCEEDED(hr))             {                 CComBSTR serviceName;                 pNewService->get_ServiceName(&serviceName);                   if (serviceName == 'FooBar')                 {                     pService->DoSomething();                 }                 else                     cout << 'Unexpected service';                  pNewService->Release();              }              pService->Release();         }          pNewProviderPtr->Release();     }     else         cout << 'Failed to query for IServiceProvider2';      pNewProvider.Release();     CoUninitialize ();   //DeInitialize all COM Components  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Use gmmktime. May 11, 2026 at 11:34 am
  • added an answer The WindowClosingEvent will be fired if a User attempts to… May 11, 2026 at 11:34 am
  • added an answer You can't order a dict per se, but you can… May 11, 2026 at 11:34 am

Related Questions

Due to company constraints out of my control, I have the following scenario: A
My company, a C++ house, is always looking to hire recent grads. However due
Due to repetitive errors with one of our Java applications: Engine engine_0: Error in
Due to continuing crash problems, I'm about to uninstall and reinstall my copy of
Due to the lack of clientaccesspolicy.xml, there appears to be problems with using Amazon
Due to a lack of response to my original question , probably due to
Due to the nature of the live server I deploy to, my mail settings
Due to a weird request, I can't put null in a database if there
Due to lack of capital and time we are having to do our game
According to this article rebasing is not necessary for .NET assemblies due to JIT

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.