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)
SYMPTOMSWhen 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.CAUSEThis problem occurs in the following scenario: - 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.
- When you call to the Regasm tool, Visual Studio .NET creates a type library and a COM Callable Wrapper (CCW)
Interop assembly.
- The type library is registered and acts as a COM object to gain access to the .NET assembly.
- 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.
RESOLUTIONTo 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
<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
- 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.
STATUS This
behavior is by design.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: | Major | Last Reviewed: | 4/9/2003 |
---|
Keywords: | kbRegistry kbDLL kbCOMInterop kbprb KB813809 kbAudDeveloper |
---|
|