PRB: IntelliSense Features Do Not Appear in Visual Basic 6.0 for .NET COM Interop Components (813809)



The information in this article applies to:

  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

SYMPTOMS

When you register a Microsoft Visual Basic .NET Component for COM Interop in the registry by using the Register for COM Interop option in Visual Studio .NET, the IntelliSense features for the methods and properties of the classes do not appear in your Visual Basic 6.0 application. Also, you cannot use early binding to bind to a method or a property.

CAUSE

This problem occurs in the following scenario:
  1. When you use the Register for COM Interop option, the Visual Studio .NET build process calls the Regasm tool with the /TLB and /CODEBASE options to register the .NET Component for COM Interop.
  2. When you call to the Regasm tool, Visual Studio .NET creates a type library and a COM Callable Wrapper (CCW) Interop assembly.
  3. The type library is registered and acts as a COM object to gain access to the .NET assembly.
  4. By default, the Regasm tool creates a type library that exposes a non-dual, empty IDispatch interface. Therefore, you cannot use early binding. If you do not use early binding, the IntelliSense features do not appear.

RESOLUTION

To resolve this problem, define a public interface by using methods and properties that you want to expose in the TLB, and then implement the interface in the class. Also, add the ClassInterface (ClassInterfaceType.None) attribute to the class. As you develop the component, you can use this approach to avoid using the ComVisible(False) attribute. The code in the following steps demonstrates how to do this:
  1. Create a new Class Library project by using Visual Basic .NET. Name the project MyClassLibrary. By default, Class1 is created.
  2. Replace the existing code with the following code:
    Option Strict On
    Imports System
    Imports System.Runtime.InteropServices
    
    Namespace MyClassLibrary
       ' Interface with members to be exposed in the TLB
       Public Interface IMyInterface
          Function MyFunction() As String
          Property MyProperty() As Int32
       End Interface
    
       ' Class that implements the Interface
       <ClassInterface(ClassInterfaceType.None)> _
          Public Class MyTestClass : Implements IMyInterface
          Public Function MyFunction() As String Implements IMyInterface.MyFunction
             Return "You have successfully accessed Visual Basic .NET library."
          End Function
    
          Public Property MyProperty() As Integer Implements IMyInterface.MyProperty
             Get
                Return 100
             End Get
             Set(ByVal Value As Integer)
    
             End Set
          End Property
       End Class
    End Namespace
    
  3. In Solution Explorer, right-click the project name, and then click Properties.
  4. Expand Configuration Properties, and then click Build.
  5. Click to select the Register for COM interop check box.
  6. On the Build menu, click Build Solution to create MyClassLibrary.dll.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new Class Library project by using Visual Basic .NET. Name the project MyTestClassLibrary. By default, Class1 is created.
  2. Replace the existing code with the following code:
    Option Strict On
    Imports System
    Imports System.Runtime.InteropServices
    
    Namespace MyTestClassLibrary
          Public Class MyTestClass 
          Public Function MyFunction() As String 
             Return "You have successfully accessed Visual Basic .NET library."
          End Function
    
          Public Property MyProperty() As Integer
             Get
                Return 100
             End Get
             Set(ByVal Value As Integer)
    
             End Set
          End Property
       End Class
    End Namespace
    
  3. In Solution Explorer, right-click the project name, and then click Properties.
  4. Expand Configuration Properties, and then click Build.
  5. Do one of the following:
    • In Visual Basic .NET, click to select the Register for COM interop check box.

      -or-
    • In Visual C# .NET, set the Register for COM interop property to true.
  6. On the Build menu, click Build Solution to create MyTestClassLibrary.dll.
  7. Create a new Standard Exe project in Visual Basic 6.0.
  8. On the Project menu, click References.
  9. In the References list, double-click to select MyTestClassLibrary and then click OK.
  10. Double-click Form1 to open the Form_Load event code.
  11. Type the following code. Note that the IntelliSense feature does not appear when you type the method name.
    ' Create an instance of .NET Component.
       Dim obj As New MyTestClassLibrary.MyTestClass
       ' Note that the IntelliSense feature does not show MyFunction.
       MsgBox obj.MyFunction
    

REFERENCES

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

316163 PRB: Error Message When You Attempt to Build a Class Library Project: COM Interop Registration Failed



Modification Type:MajorLast Reviewed:4/9/2003
Keywords:kbRegistry kbDLL kbCOMInterop kbprb KB813809 kbAudDeveloper