Microsoft KB Archive/813809

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

Article ID: 813809

Article Last Modified on 4/9/2003

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



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:  Create a new Class Library project by using Visual Basic .NET. Name the project MyClassLibrary. By default, Class1 is created.  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  _ Public Class MyTestClass : Implements IMyInterface Public Function MyFunction As String Implements IMyInterface.MyFunction Return &quot;You have successfully accessed Visual Basic .NET library.&quot; 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  In Solution Explorer, right-click the project name, and then click Properties. Expand Configuration Properties, and then click Build. Click to select the Register for COM interop check box. On the Build menu, click Build Solution to create MyClassLibrary.dll.</li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to Reproduce the Behavior
<ol> Create a new Class Library project by using Visual Basic .NET. Name the project MyTestClassLibrary. By default, Class1 is created.</li>  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 &quot;You have successfully accessed Visual Basic .NET library.&quot; 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 </li> In Solution Explorer, right-click the project name, and then click Properties.</li> Expand Configuration Properties, and then click Build.</li> Do one of the following: <ul> In Visual Basic .NET, click to select the Register for COM interop check box.

-or-</li> In Visual C# .NET, set the Register for COM interop property to true.</li></ul> </li> On the Build menu, click Build Solution to create MyTestClassLibrary.dll.</li> Create a new Standard Exe project in Visual Basic 6.0.</li> On the Project menu, click References.</li> In the References list, double-click to select MyTestClassLibrary and then click OK.</li> Double-click Form1 to open the Form_Load event code.</li>  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 </li></ol>

<div class="references_section">