Access a .Net COM object hosted in a COM+ Server in .Net? RRS feed

  • Question


    I have a COM component written in .Net and hosted in a COM+ server application so that only 1 instance of the component will exist on a box at a given time (singleton). Multiple different applications will be accessing the COM component: Matlab, VB Script, .Net application, etc...

    When the COM component is instantiated from VB Script or Matlab, I can see the COM+ server starting properly and can verify that only 1 instance of my component object is created.

    My problem arises when the COM component consumer is a .Net application. Basically, it seems .Net always resolves the location of the DLL and since it is a .Net DLL, always instantiates the object directly, skipping the COM+ mechanism. It seems obvious why .Net behaves that way to get rid of COM overhead, but this is causing problems in my design since I want only a single instance of my COM Component to exist on a box at one time.

    So the question is how can I instantiate a .Net based COM component hosted in a COM+ server application from a .Net application by using the COM+ mechanism?

    Monday, January 19, 2009 10:08 AM

All replies

  • Just as a note, after registering my .Net written COM Component and adding it to a COM+ server application, I have attempted the following without success:

    Type type = Type.GetTypeFromProgID("MyDotNetCOMComponent.ComponentClass");

    ComponentClass component = Activator.CreateInstance(type) as ComponentClass ;

    This call successfully creates an instance of my ComponentClass, but the COM+ server application is not started. Instead, if from VB Script I call:

    Set test = WScript.CreateObject("MyDotNetCOMComponent.ComponentClass")

    I can then see the COM+ server start and can verify that it is possible to provide a single instance of my COM object to all consumer applications.

    Thanks for your help.

    Monday, January 19, 2009 10:14 AM