Adding a VB6 link to Visual Studio gives "The importer of the type library encountered an error during type checking"

I am going to convert a rather large project written in VB6 to C #. Given the size of the project being moved, it is carried out in stages over a period of 18 months. I had a problem adding a link to a VB6 ActiveX DLL to a .Net project.

If you follow these steps, you can recreate the problem too.

I wrote an interface in .Net that is COM visible:

<ComVisible(True)> Public Interface ITestInterface Property A As String Function TestMethod() As String End Interface 

Selecting “Registration for COM-interaction” on the “Compilation” tab of the project properties, you will receive a TLB file.

I created a VB6 project that references this TLB and a class that implements the interface.

 Implements ITestInterface Private mA As String Public Property Get ITestInterface_A() As String ITestInterface_A = mA End Property Public Property Let ITestInterface_A(ByVal value As String) mA = value End Property Public Function ITestInterface_TestMethod() As String ITestInterface_TestMethod = "From VB6" End Function 

If I set the “Component” tab of the project properties in VB6 to use “remote server files”, then a TLB is automatically created at compilation. I can view this TLB in OleView and see the following (in addition to the details of a specific implementation made in the VB6 interface defined in the .Net project):

 // typelib filename: TestVB6Interface.dll [ uuid(**EF005573-BFC7-436D-A382-F906CA09F94A**), version(3.0) ] // ... some other stuff // TLib : // TLib : : {79EC733A-0267-4506-8D38-C4D4655E0755} importlib("SimpleDotNetLibrary.tlb"); 

Now I am creating a completely new .Net project. If I add a link to the VB6 dll, I get the following error:

Failed to resolve COM link " ef005573-bfc7-436d-a382-f906ca09f94a " version 3.0. The importer of the type library encountered an error while checking the type. Try importing without classes.

However, if I run the Visual Studio command prompt and run the following:

 tlbimp TestVB6Interface.tlb /out:TestVB6Interface.MyInterop.dll 

Then I can add this dll as a link in my .Net solution, and it works fine.

My question is. What does tlbimp do on the command line, which fails when I just add the link directly? When a message in Visual Studio says “try importing without class members”, how exactly do I do it in Visual Studio? I know how to do this in tlbimp.

I apologize for the wall of the text, but I wanted to describe the situation as best as possible so that the information I felt was relevant.

+8
c # visual-studio-2010 vb6 tlbimp
source share
1 answer

The Visual Studio IDE definitely uses a different path when registering a DLL for COM Interop, and then when starting command-line tools from the command line.

I doubt that Microsoft has documented this anywhere. However, my many years of experience have proven that this is so. One day I came across a situation where the "regsvcs" command from the .NET 2.0 Framework would actually cause an infinite loop. If you are Google, you are likely to find others who have had this problem. I was able to take this one step further using the VS IDE to register the .NET Serviced COM component. However, this inevitably ended in a mistake. The mistake was a step forward in an infinite loop. In any case, it seemed to me that the VS IDE uses a different code path / business logic when working with COM Interop and registry messages.

+2
source share

All Articles