Home > database >  COM interop project does not generate tlb file
COM interop project does not generate tlb file

Time:08-25

I'm making a C# project where it will be consumed by a VB6 application using a COM interop. But I can't make the VB6 application consume this DLL. In my research I saw that to work it is necessary to generate a .tlb file but I don't know how to generate it.

I have an interface:

[Guid("7A5DA013-C6AA-4327-96C8-096D3F217778"), ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IConnectionAPI
{
    [DispId(1)]
    ADODB.Recordset Get(string URL, string parametros);

    [DispId(2)]
    ADODB.Recordset Post(string URL, string parametros);
}

And I have the class implementing this interface:

[ProgId("Interop.ConnectionAPI"), Guid("51CA97D0-2630-46C8-A899-33CD12379FBE"), ComVisible(true)]
public class ConnectionAPI : IConnectionAPI
{
    public Recordset Get(string URL, string parametros)
    {
        return null;
    }

    public Recordset Post(string URL, string parameters)
    {
        Recordset returnVB6 = null;
        using (HTTP.HTTP_helper httpPost = new HTTP.HTTP_helper())
        {
            string response = httpPost.HttpPost(URL, parameters);
            
            DataTable dtData = JsonConvert.DeserializeObject<DataTable>(response);
            returnVB6 = VB6_helper.ConvertDataTableToRecordset(dtData);
        }

        return returnVB6;

    }

}

CodePudding user response:

The first one, in your project go to Properties-Build and check the option "Register for COM interop". With this, when building your project, it will generate the .tlb file.

enter image description here

Here you will also find information on the subject for when you need to generate this file in a different environment than the development one.

  • Related