Use .NET component in COM + application

1

In my company there is a asp application that interacts with COM + components made in Visual Basic 6 and one of those COM + components interacts with a component made with .NET C #, for which the type library had to be created ( tlb) for the .NET component and add it as a reference in VB6. In VB6 for this component binary compatibility is configured. We have test server and production server. I recently had to make an adjustment to the COM + component and the .NET C # component, and placing them on the test server, it worked fine, several successful tests were performed. However, when it was released to the production environment, the COM + component throws an exception error:

  

ActiveX component can not create the object.

I do not understand why the error since the COM + component is registered by RegSvr32 in both environments and both the DLL and the .NET TLB are available in the same COM + route.

    
asked by user2403459 24.02.2016 в 22:07
source

1 answer

1

Most likely the cause of the error is the registration of the component developed in .NET

As far as I remember, these components are registered using the Regasm.exe utility. and it is when using this utility when the file TLB is generated that is the one that you will import from VB6 (I did it from Delphi)

Also, your .NET class should be decorated with the ComVisible and you also have to have this attribute at the assembly level.

The .NET component could also be implemented by inheriting from ServicedComponent , in which case the utility to register it is Regsvcs.exe

Two tricks that avoid many problems are:

  • Create a default interface for the object that we want to be visible to COM (this prevents you from generating an interface that is difficult to control automatically)
  • Assign GUIDs specific to both the Interface and the class (this prevents you from registering a different GUID to the one you have referenced from VB6)

The implementation would look something like this:

[ComVisible(true), Guid("AF2FD61E-0BD6-4217-852A-236D3376CB60")]
public interface IMiObjetoCOM
{
    ..
}

[ComVisible(true)]
[Guid("F64CD35B-43AF-4EFE-93ED-D5A5522CD1A4")]
[ClassInterface(ClassInterfaceType.None)]
public class MiObjetoCom: IMyObjetoCOM
{
    ..
}
    
answered by 24.02.2016 / 22:55
source